...

Source file src/github.com/go-playground/locales/lb/lb.go

Documentation: github.com/go-playground/locales/lb

     1  package lb
     2  
     3  import (
     4  	"math"
     5  	"strconv"
     6  	"time"
     7  
     8  	"github.com/go-playground/locales"
     9  	"github.com/go-playground/locales/currency"
    10  )
    11  
    12  type lb struct {
    13  	locale                 string
    14  	pluralsCardinal        []locales.PluralRule
    15  	pluralsOrdinal         []locales.PluralRule
    16  	pluralsRange           []locales.PluralRule
    17  	decimal                string
    18  	group                  string
    19  	minus                  string
    20  	percent                string
    21  	percentSuffix          string
    22  	perMille               string
    23  	timeSeparator          string
    24  	inifinity              string
    25  	currencies             []string // idx = enum of currency code
    26  	currencyPositiveSuffix string
    27  	currencyNegativeSuffix string
    28  	monthsAbbreviated      []string
    29  	monthsNarrow           []string
    30  	monthsWide             []string
    31  	daysAbbreviated        []string
    32  	daysNarrow             []string
    33  	daysShort              []string
    34  	daysWide               []string
    35  	periodsAbbreviated     []string
    36  	periodsNarrow          []string
    37  	periodsShort           []string
    38  	periodsWide            []string
    39  	erasAbbreviated        []string
    40  	erasNarrow             []string
    41  	erasWide               []string
    42  	timezones              map[string]string
    43  }
    44  
    45  // New returns a new instance of translator for the 'lb' locale
    46  func New() locales.Translator {
    47  	return &lb{
    48  		locale:                 "lb",
    49  		pluralsCardinal:        []locales.PluralRule{2, 6},
    50  		pluralsOrdinal:         nil,
    51  		pluralsRange:           nil,
    52  		decimal:                ",",
    53  		group:                  ".",
    54  		minus:                  "-",
    55  		percent:                "%",
    56  		perMille:               "‰",
    57  		timeSeparator:          ":",
    58  		inifinity:              "∞",
    59  		currencies:             []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "öS", "AU$", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "FJD", "FKP", "FRF", "£", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MRU", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MX$", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZ$", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR", "SVC", "SYP", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "UYW", "UZS", "VEB", "VEF", "VES", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
    60  		percentSuffix:          " ",
    61  		currencyPositiveSuffix: " ",
    62  		currencyNegativeSuffix: " ",
    63  		monthsAbbreviated:      []string{"", "Jan.", "Feb.", "Mäe.", "Abr.", "Mee", "Juni", "Juli", "Aug.", "Sep.", "Okt.", "Nov.", "Dez."},
    64  		monthsNarrow:           []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
    65  		monthsWide:             []string{"", "Januar", "Februar", "Mäerz", "Abrëll", "Mee", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"},
    66  		daysAbbreviated:        []string{"Son.", "Méi.", "Dën.", "Mët.", "Don.", "Fre.", "Sam."},
    67  		daysNarrow:             []string{"S", "M", "D", "M", "D", "F", "S"},
    68  		daysShort:              []string{"So.", "Mé.", "Dë.", "Më.", "Do.", "Fr.", "Sa."},
    69  		daysWide:               []string{"Sonndeg", "Méindeg", "Dënschdeg", "Mëttwoch", "Donneschdeg", "Freideg", "Samschdeg"},
    70  		periodsAbbreviated:     []string{"moies", "nomëttes"},
    71  		periodsNarrow:          []string{"mo.", "nomë."},
    72  		periodsWide:            []string{"moies", "nomëttes"},
    73  		erasAbbreviated:        []string{"v. Chr.", "n. Chr."},
    74  		erasNarrow:             []string{"", ""},
    75  		erasWide:               []string{"v. Chr.", "n. Chr."},
    76  		timezones:              map[string]string{"ACDT": "Zentralaustralesch Summerzäit", "ACST": "Zentralaustralesch Normalzäit", "ACWDT": "Zentral-/Westaustralesch Summerzäit", "ACWST": "Zentral-/Westaustralesch Normalzäit", "ADT": "Atlantik-Summerzäit", "AEDT": "Ostaustralesch Summerzäit", "AEST": "Ostaustralesch Normalzäit", "AKDT": "Alaska-Summerzäit", "AKST": "Alaska-Normalzäit", "ARST": "Argentinesch Summerzäit", "ART": "Argentinesch Normalzäit", "AST": "Atlantik-Normalzäit", "AWDT": "Westaustralesch Summerzäit", "AWST": "Westaustralesch Normalzäit", "BOT": "Bolivianesch Zäit", "BT": "Bhutan-Zäit", "CAT": "Zentralafrikanesch Zäit", "CDT": "Nordamerikanesch Inland-Summerzäit", "CHADT": "Chatham-Summerzäit", "CHAST": "Chatham-Normalzäit", "CLST": "Chilenesch Summerzäit", "CLT": "Chilenesch Normalzäit", "COST": "Kolumbianesch Summerzäit", "COT": "Kolumbianesch Normalzäit", "CST": "Nordamerikanesch Inland-Normalzäit", "ChST": "Chamorro-Zäit", "EAT": "Ostafrikanesch Zäit", "ECT": "Ecuadorianesch Zäit", "EDT": "Nordamerikanesch Ostküsten-Summerzäit", "EST": "Nordamerikanesch Ostküsten-Normalzäit", "GFT": "Franséisch-Guayane-Zäit", "GMT": "Mëttler Greenwich-Zäit", "GST": "Golf-Zäit", "GYT": "Guyana-Zäit", "HADT": "Hawaii-Aleuten-Summerzäit", "HAST": "Hawaii-Aleuten-Normalzäit", "HAT": "Neifundland-Summerzäit", "HECU": "Kubanesch Summerzäit", "HEEG": "Ostgrönland-Summerzäit", "HENOMX": "Nordwest-Mexiko-Summerzäit", "HEOG": "Westgrönland-Summerzäit", "HEPM": "Saint-Pierre-a-Miquelon-Summerzäit", "HEPMX": "Mexikanesch Pazifik-Summerzäit", "HKST": "Hong-Kong-Summerzäit", "HKT": "Hong-Kong-Normalzäit", "HNCU": "Kubanesch Normalzäit", "HNEG": "Ostgrönland-Normalzäit", "HNNOMX": "Nordwest-Mexiko-Normalzäit", "HNOG": "Westgrönland-Normalzäit", "HNPM": "Saint-Pierre-a-Miquelon-Normalzäit", "HNPMX": "Mexikanesch Pazifik-Normalzäit", "HNT": "Neifundland-Normalzäit", "IST": "Indesch Zäit", "JDT": "Japanesch Summerzäit", "JST": "Japanesch Normalzäit", "LHDT": "Lord-Howe-Summerzäit", "LHST": "Lord-Howe-Normalzäit", "MDT": "Rocky-Mountain-Summerzäit", "MESZ": "Mëtteleuropäesch Summerzäit", "MEZ": "Mëtteleuropäesch Normalzäit", "MST": "Rocky-Mountain-Normalzäit", "MYT": "Malaysesch Zäit", "NZDT": "Neiséiland-Summerzäit", "NZST": "Neiséiland-Normalzäit", "OESZ": "Osteuropäesch Summerzäit", "OEZ": "Osteuropäesch Normalzäit", "PDT": "Nordamerikanesch Westküsten-Summerzäit", "PST": "Nordamerikanesch Westküsten-Normalzäit", "SAST": "Südafrikanesch Zäit", "SGT": "Singapur-Standardzäit", "SRT": "Suriname-Zäit", "TMST": "Turkmenistan-Summerzäit", "TMT": "Turkmenistan-Normalzäit", "UYST": "Uruguayanesch Summerzäit", "UYT": "Uruguyanesch Normalzäit", "VET": "Venezuela-Zäit", "WARST": "Westargentinesch Summerzäit", "WART": "Westargentinesch Normalzäit", "WAST": "Westafrikanesch Summerzäit", "WAT": "Westafrikanesch Normalzäit", "WESZ": "Westeuropäesch Summerzäit", "WEZ": "Westeuropäesch Normalzäit", "WIB": "Westindonesesch Zäit", "WIT": "Ostindonesesch Zäit", "WITA": "Zentralindonesesch Zäit", "∅∅∅": "Brasília-Summerzäit"},
    77  	}
    78  }
    79  
    80  // Locale returns the current translators string locale
    81  func (lb *lb) Locale() string {
    82  	return lb.locale
    83  }
    84  
    85  // PluralsCardinal returns the list of cardinal plural rules associated with 'lb'
    86  func (lb *lb) PluralsCardinal() []locales.PluralRule {
    87  	return lb.pluralsCardinal
    88  }
    89  
    90  // PluralsOrdinal returns the list of ordinal plural rules associated with 'lb'
    91  func (lb *lb) PluralsOrdinal() []locales.PluralRule {
    92  	return lb.pluralsOrdinal
    93  }
    94  
    95  // PluralsRange returns the list of range plural rules associated with 'lb'
    96  func (lb *lb) PluralsRange() []locales.PluralRule {
    97  	return lb.pluralsRange
    98  }
    99  
   100  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'lb'
   101  func (lb *lb) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
   102  
   103  	n := math.Abs(num)
   104  
   105  	if n == 1 {
   106  		return locales.PluralRuleOne
   107  	}
   108  
   109  	return locales.PluralRuleOther
   110  }
   111  
   112  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'lb'
   113  func (lb *lb) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   114  	return locales.PluralRuleUnknown
   115  }
   116  
   117  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'lb'
   118  func (lb *lb) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   119  	return locales.PluralRuleUnknown
   120  }
   121  
   122  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   123  func (lb *lb) MonthAbbreviated(month time.Month) string {
   124  	return lb.monthsAbbreviated[month]
   125  }
   126  
   127  // MonthsAbbreviated returns the locales abbreviated months
   128  func (lb *lb) MonthsAbbreviated() []string {
   129  	return lb.monthsAbbreviated[1:]
   130  }
   131  
   132  // MonthNarrow returns the locales narrow month given the 'month' provided
   133  func (lb *lb) MonthNarrow(month time.Month) string {
   134  	return lb.monthsNarrow[month]
   135  }
   136  
   137  // MonthsNarrow returns the locales narrow months
   138  func (lb *lb) MonthsNarrow() []string {
   139  	return lb.monthsNarrow[1:]
   140  }
   141  
   142  // MonthWide returns the locales wide month given the 'month' provided
   143  func (lb *lb) MonthWide(month time.Month) string {
   144  	return lb.monthsWide[month]
   145  }
   146  
   147  // MonthsWide returns the locales wide months
   148  func (lb *lb) MonthsWide() []string {
   149  	return lb.monthsWide[1:]
   150  }
   151  
   152  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   153  func (lb *lb) WeekdayAbbreviated(weekday time.Weekday) string {
   154  	return lb.daysAbbreviated[weekday]
   155  }
   156  
   157  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   158  func (lb *lb) WeekdaysAbbreviated() []string {
   159  	return lb.daysAbbreviated
   160  }
   161  
   162  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   163  func (lb *lb) WeekdayNarrow(weekday time.Weekday) string {
   164  	return lb.daysNarrow[weekday]
   165  }
   166  
   167  // WeekdaysNarrow returns the locales narrow weekdays
   168  func (lb *lb) WeekdaysNarrow() []string {
   169  	return lb.daysNarrow
   170  }
   171  
   172  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   173  func (lb *lb) WeekdayShort(weekday time.Weekday) string {
   174  	return lb.daysShort[weekday]
   175  }
   176  
   177  // WeekdaysShort returns the locales short weekdays
   178  func (lb *lb) WeekdaysShort() []string {
   179  	return lb.daysShort
   180  }
   181  
   182  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   183  func (lb *lb) WeekdayWide(weekday time.Weekday) string {
   184  	return lb.daysWide[weekday]
   185  }
   186  
   187  // WeekdaysWide returns the locales wide weekdays
   188  func (lb *lb) WeekdaysWide() []string {
   189  	return lb.daysWide
   190  }
   191  
   192  // Decimal returns the decimal point of number
   193  func (lb *lb) Decimal() string {
   194  	return lb.decimal
   195  }
   196  
   197  // Group returns the group of number
   198  func (lb *lb) Group() string {
   199  	return lb.group
   200  }
   201  
   202  // Group returns the minus sign of number
   203  func (lb *lb) Minus() string {
   204  	return lb.minus
   205  }
   206  
   207  // FmtNumber returns 'num' with digits/precision of 'v' for 'lb' and handles both Whole and Real numbers based on 'v'
   208  func (lb *lb) FmtNumber(num float64, v uint64) string {
   209  
   210  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   211  	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
   212  	count := 0
   213  	inWhole := v == 0
   214  	b := make([]byte, 0, l)
   215  
   216  	for i := len(s) - 1; i >= 0; i-- {
   217  
   218  		if s[i] == '.' {
   219  			b = append(b, lb.decimal[0])
   220  			inWhole = true
   221  			continue
   222  		}
   223  
   224  		if inWhole {
   225  			if count == 3 {
   226  				b = append(b, lb.group[0])
   227  				count = 1
   228  			} else {
   229  				count++
   230  			}
   231  		}
   232  
   233  		b = append(b, s[i])
   234  	}
   235  
   236  	if num < 0 {
   237  		b = append(b, lb.minus[0])
   238  	}
   239  
   240  	// reverse
   241  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   242  		b[i], b[j] = b[j], b[i]
   243  	}
   244  
   245  	return string(b)
   246  }
   247  
   248  // FmtPercent returns 'num' with digits/precision of 'v' for 'lb' and handles both Whole and Real numbers based on 'v'
   249  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   250  func (lb *lb) FmtPercent(num float64, v uint64) string {
   251  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   252  	l := len(s) + 5
   253  	b := make([]byte, 0, l)
   254  
   255  	for i := len(s) - 1; i >= 0; i-- {
   256  
   257  		if s[i] == '.' {
   258  			b = append(b, lb.decimal[0])
   259  			continue
   260  		}
   261  
   262  		b = append(b, s[i])
   263  	}
   264  
   265  	if num < 0 {
   266  		b = append(b, lb.minus[0])
   267  	}
   268  
   269  	// reverse
   270  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   271  		b[i], b[j] = b[j], b[i]
   272  	}
   273  
   274  	b = append(b, lb.percentSuffix...)
   275  
   276  	b = append(b, lb.percent...)
   277  
   278  	return string(b)
   279  }
   280  
   281  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'lb'
   282  func (lb *lb) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   283  
   284  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   285  	symbol := lb.currencies[currency]
   286  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   287  	count := 0
   288  	inWhole := v == 0
   289  	b := make([]byte, 0, l)
   290  
   291  	for i := len(s) - 1; i >= 0; i-- {
   292  
   293  		if s[i] == '.' {
   294  			b = append(b, lb.decimal[0])
   295  			inWhole = true
   296  			continue
   297  		}
   298  
   299  		if inWhole {
   300  			if count == 3 {
   301  				b = append(b, lb.group[0])
   302  				count = 1
   303  			} else {
   304  				count++
   305  			}
   306  		}
   307  
   308  		b = append(b, s[i])
   309  	}
   310  
   311  	if num < 0 {
   312  		b = append(b, lb.minus[0])
   313  	}
   314  
   315  	// reverse
   316  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   317  		b[i], b[j] = b[j], b[i]
   318  	}
   319  
   320  	if int(v) < 2 {
   321  
   322  		if v == 0 {
   323  			b = append(b, lb.decimal...)
   324  		}
   325  
   326  		for i := 0; i < 2-int(v); i++ {
   327  			b = append(b, '0')
   328  		}
   329  	}
   330  
   331  	b = append(b, lb.currencyPositiveSuffix...)
   332  
   333  	b = append(b, symbol...)
   334  
   335  	return string(b)
   336  }
   337  
   338  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'lb'
   339  // in accounting notation.
   340  func (lb *lb) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   341  
   342  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   343  	symbol := lb.currencies[currency]
   344  	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
   345  	count := 0
   346  	inWhole := v == 0
   347  	b := make([]byte, 0, l)
   348  
   349  	for i := len(s) - 1; i >= 0; i-- {
   350  
   351  		if s[i] == '.' {
   352  			b = append(b, lb.decimal[0])
   353  			inWhole = true
   354  			continue
   355  		}
   356  
   357  		if inWhole {
   358  			if count == 3 {
   359  				b = append(b, lb.group[0])
   360  				count = 1
   361  			} else {
   362  				count++
   363  			}
   364  		}
   365  
   366  		b = append(b, s[i])
   367  	}
   368  
   369  	if num < 0 {
   370  
   371  		b = append(b, lb.minus[0])
   372  
   373  	}
   374  
   375  	// reverse
   376  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   377  		b[i], b[j] = b[j], b[i]
   378  	}
   379  
   380  	if int(v) < 2 {
   381  
   382  		if v == 0 {
   383  			b = append(b, lb.decimal...)
   384  		}
   385  
   386  		for i := 0; i < 2-int(v); i++ {
   387  			b = append(b, '0')
   388  		}
   389  	}
   390  
   391  	if num < 0 {
   392  		b = append(b, lb.currencyNegativeSuffix...)
   393  		b = append(b, symbol...)
   394  	} else {
   395  
   396  		b = append(b, lb.currencyPositiveSuffix...)
   397  		b = append(b, symbol...)
   398  	}
   399  
   400  	return string(b)
   401  }
   402  
   403  // FmtDateShort returns the short date representation of 't' for 'lb'
   404  func (lb *lb) FmtDateShort(t time.Time) string {
   405  
   406  	b := make([]byte, 0, 32)
   407  
   408  	if t.Day() < 10 {
   409  		b = append(b, '0')
   410  	}
   411  
   412  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   413  	b = append(b, []byte{0x2e}...)
   414  
   415  	if t.Month() < 10 {
   416  		b = append(b, '0')
   417  	}
   418  
   419  	b = strconv.AppendInt(b, int64(t.Month()), 10)
   420  
   421  	b = append(b, []byte{0x2e}...)
   422  
   423  	if t.Year() > 9 {
   424  		b = append(b, strconv.Itoa(t.Year())[2:]...)
   425  	} else {
   426  		b = append(b, strconv.Itoa(t.Year())[1:]...)
   427  	}
   428  
   429  	return string(b)
   430  }
   431  
   432  // FmtDateMedium returns the medium date representation of 't' for 'lb'
   433  func (lb *lb) FmtDateMedium(t time.Time) string {
   434  
   435  	b := make([]byte, 0, 32)
   436  
   437  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   438  	b = append(b, []byte{0x2e, 0x20}...)
   439  	b = append(b, lb.monthsAbbreviated[t.Month()]...)
   440  	b = append(b, []byte{0x20}...)
   441  
   442  	if t.Year() > 0 {
   443  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   444  	} else {
   445  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   446  	}
   447  
   448  	return string(b)
   449  }
   450  
   451  // FmtDateLong returns the long date representation of 't' for 'lb'
   452  func (lb *lb) FmtDateLong(t time.Time) string {
   453  
   454  	b := make([]byte, 0, 32)
   455  
   456  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   457  	b = append(b, []byte{0x2e, 0x20}...)
   458  	b = append(b, lb.monthsWide[t.Month()]...)
   459  	b = append(b, []byte{0x20}...)
   460  
   461  	if t.Year() > 0 {
   462  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   463  	} else {
   464  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   465  	}
   466  
   467  	return string(b)
   468  }
   469  
   470  // FmtDateFull returns the full date representation of 't' for 'lb'
   471  func (lb *lb) FmtDateFull(t time.Time) string {
   472  
   473  	b := make([]byte, 0, 32)
   474  
   475  	b = append(b, lb.daysWide[t.Weekday()]...)
   476  	b = append(b, []byte{0x2c, 0x20}...)
   477  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   478  	b = append(b, []byte{0x2e, 0x20}...)
   479  	b = append(b, lb.monthsWide[t.Month()]...)
   480  	b = append(b, []byte{0x20}...)
   481  
   482  	if t.Year() > 0 {
   483  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   484  	} else {
   485  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   486  	}
   487  
   488  	return string(b)
   489  }
   490  
   491  // FmtTimeShort returns the short time representation of 't' for 'lb'
   492  func (lb *lb) FmtTimeShort(t time.Time) string {
   493  
   494  	b := make([]byte, 0, 32)
   495  
   496  	if t.Hour() < 10 {
   497  		b = append(b, '0')
   498  	}
   499  
   500  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   501  	b = append(b, lb.timeSeparator...)
   502  
   503  	if t.Minute() < 10 {
   504  		b = append(b, '0')
   505  	}
   506  
   507  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   508  
   509  	return string(b)
   510  }
   511  
   512  // FmtTimeMedium returns the medium time representation of 't' for 'lb'
   513  func (lb *lb) FmtTimeMedium(t time.Time) string {
   514  
   515  	b := make([]byte, 0, 32)
   516  
   517  	if t.Hour() < 10 {
   518  		b = append(b, '0')
   519  	}
   520  
   521  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   522  	b = append(b, lb.timeSeparator...)
   523  
   524  	if t.Minute() < 10 {
   525  		b = append(b, '0')
   526  	}
   527  
   528  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   529  	b = append(b, lb.timeSeparator...)
   530  
   531  	if t.Second() < 10 {
   532  		b = append(b, '0')
   533  	}
   534  
   535  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   536  
   537  	return string(b)
   538  }
   539  
   540  // FmtTimeLong returns the long time representation of 't' for 'lb'
   541  func (lb *lb) FmtTimeLong(t time.Time) string {
   542  
   543  	b := make([]byte, 0, 32)
   544  
   545  	if t.Hour() < 10 {
   546  		b = append(b, '0')
   547  	}
   548  
   549  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   550  	b = append(b, lb.timeSeparator...)
   551  
   552  	if t.Minute() < 10 {
   553  		b = append(b, '0')
   554  	}
   555  
   556  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   557  	b = append(b, lb.timeSeparator...)
   558  
   559  	if t.Second() < 10 {
   560  		b = append(b, '0')
   561  	}
   562  
   563  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   564  	b = append(b, []byte{0x20}...)
   565  
   566  	tz, _ := t.Zone()
   567  	b = append(b, tz...)
   568  
   569  	return string(b)
   570  }
   571  
   572  // FmtTimeFull returns the full time representation of 't' for 'lb'
   573  func (lb *lb) FmtTimeFull(t time.Time) string {
   574  
   575  	b := make([]byte, 0, 32)
   576  
   577  	if t.Hour() < 10 {
   578  		b = append(b, '0')
   579  	}
   580  
   581  	b = strconv.AppendInt(b, int64(t.Hour()), 10)
   582  	b = append(b, lb.timeSeparator...)
   583  
   584  	if t.Minute() < 10 {
   585  		b = append(b, '0')
   586  	}
   587  
   588  	b = strconv.AppendInt(b, int64(t.Minute()), 10)
   589  	b = append(b, lb.timeSeparator...)
   590  
   591  	if t.Second() < 10 {
   592  		b = append(b, '0')
   593  	}
   594  
   595  	b = strconv.AppendInt(b, int64(t.Second()), 10)
   596  	b = append(b, []byte{0x20}...)
   597  
   598  	tz, _ := t.Zone()
   599  
   600  	if btz, ok := lb.timezones[tz]; ok {
   601  		b = append(b, btz...)
   602  	} else {
   603  		b = append(b, tz...)
   604  	}
   605  
   606  	return string(b)
   607  }
   608  

View as plain text