1package fil 2 3import ( 4 "math" 5 "strconv" 6 "time" 7 8 "github.com/gohugoio/locales" 9 "github.com/gohugoio/locales/currency" 10) 11 12type fil 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 perMille string 22 timeSeparator string 23 inifinity string 24 currencies []string // idx = enum of currency code 25 currencyNegativePrefix string 26 currencyNegativeSuffix string 27 monthsAbbreviated []string 28 monthsNarrow []string 29 monthsWide []string 30 daysAbbreviated []string 31 daysNarrow []string 32 daysShort []string 33 daysWide []string 34 periodsAbbreviated []string 35 periodsNarrow []string 36 periodsShort []string 37 periodsWide []string 38 erasAbbreviated []string 39 erasNarrow []string 40 erasWide []string 41 timezones map[string]string 42} 43 44// New returns a new instance of translator for the 'fil' locale 45func New() locales.Translator { 46 return &fil{ 47 locale: "fil", 48 pluralsCardinal: []locales.PluralRule{2, 6}, 49 pluralsOrdinal: []locales.PluralRule{2, 6}, 50 pluralsRange: []locales.PluralRule{2, 6}, 51 decimal: ".", 52 group: ",", 53 minus: "-", 54 percent: "%", 55 perMille: "‰", 56 timeSeparator: ":", 57 inifinity: "∞", 58 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "A$", "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", "₱", "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"}, 59 currencyNegativePrefix: "(", 60 currencyNegativeSuffix: ")", 61 monthsAbbreviated: []string{"", "Ene", "Peb", "Mar", "Abr", "May", "Hun", "Hul", "Ago", "Set", "Okt", "Nob", "Dis"}, 62 monthsNarrow: []string{"", "Ene", "Peb", "Mar", "Abr", "May", "Hun", "Hul", "Ago", "Set", "Okt", "Nob", "Dis"}, 63 monthsWide: []string{"", "Enero", "Pebrero", "Marso", "Abril", "Mayo", "Hunyo", "Hulyo", "Agosto", "Setyembre", "Oktubre", "Nobyembre", "Disyembre"}, 64 daysAbbreviated: []string{"Lin", "Lun", "Mar", "Miy", "Huw", "Biy", "Sab"}, 65 daysNarrow: []string{"Lin", "Lun", "Mar", "Miy", "Huw", "Biy", "Sab"}, 66 daysShort: []string{"Li", "Lu", "Ma", "Mi", "Hu", "Bi", "Sa"}, 67 daysWide: []string{"Linggo", "Lunes", "Martes", "Miyerkules", "Huwebes", "Biyernes", "Sabado"}, 68 periodsAbbreviated: []string{"AM", "PM"}, 69 periodsNarrow: []string{"am", "pm"}, 70 periodsWide: []string{"AM", "PM"}, 71 erasAbbreviated: []string{"BC", "AD"}, 72 erasNarrow: []string{"", ""}, 73 erasWide: []string{"Before Christ", "Anno Domini"}, 74 timezones: map[string]string{"ACDT": "Daylight Time sa Gitnang Australya", "ACST": "Standard na Oras sa Gitnang Australya", "ACWDT": "Daylight Time sa Gitnang Kanlurang Australya", "ACWST": "Standard Time ng Gitnang Kanluran ng Australya", "ADT": "Daylight Time sa Atlantiko", "AEDT": "Daylight Time sa Silangang Australya", "AEST": "Standard na Oras sa Silangang Australya", "AKDT": "Daylight Time sa Alaska", "AKST": "Standard na Oras sa Alaska", "ARST": "Oras sa Tag-init ng Argentina", "ART": "Standard na Oras sa Argentina", "AST": "Standard na Oras sa Atlantiko", "AWDT": "Daylight Time sa Kanlurang Australya", "AWST": "Standard na Oras sa Kanlurang Australya", "BOT": "Oras sa Bolivia", "BT": "Oras sa Bhutan", "CAT": "Oras sa Gitnang Africa", "CDT": "Sentral na Daylight Time", "CHADT": "Daylight Time sa Chatham", "CHAST": "Standard na Oras sa Chatham", "CLST": "Oras sa Tag-init ng Chile", "CLT": "Standard na Oras sa Chile", "COST": "Oras sa Tag-init ng Colombia", "COT": "Standard na Oras sa Colombia", "CST": "Sentral na Karaniwang Oras", "ChST": "Standard na Oras sa Chamorro", "EAT": "Oras sa Silangang Africa", "ECT": "Oras sa Ecuador", "EDT": "Eastern Daylight Time", "EST": "Eastern na Standard na Oras", "GFT": "Oras sa French Guiana", "GMT": "Greenwich Mean Time", "GST": "Oras sa Gulf", "GYT": "Oras sa Guyana", "HADT": "Oras sa Tag-init ng Hawaii-Aleutian", "HAST": "Standard na Oras sa Hawaii-Aleutian", "HAT": "Daylight Time sa Newfoundland", "HECU": "Daylight Time sa Cuba", "HEEG": "Oras sa Tag-init ng Silangang Greenland", "HENOMX": "Daylight Time sa Hilagang-kanlurang Mexico", "HEOG": "Oras sa Tag-init ng Kanlurang Greenland", "HEPM": "Daylight Time sa Saint Pierre & Miquelon", "HEPMX": "Daylight Time sa Pasipiko ng Mexico", "HKST": "Oras sa Tag-init ng Hong Kong", "HKT": "Standard na Oras sa Hong Kong", "HNCU": "Standard na Oras sa Cuba", "HNEG": "Standard na Oras sa Silangang Greenland", "HNNOMX": "Standard na Oras sa Hilagang-kanlurang Mexico", "HNOG": "Standard na Oras sa Kanlurang Greenland", "HNPM": "Standard na Oras sa Saint Pierre & Miquelon", "HNPMX": "Standard na Oras sa Pasipiko ng Mexico", "HNT": "Standard na Oras sa Newfoundland", "IST": "Standard na Oras sa Bhutan", "JDT": "Daylight Time sa Japan", "JST": "Standard na Oras sa Japan", "LHDT": "Daylight Time sa Lorde Howe", "LHST": "Standard na Oras sa Lord Howe", "MDT": "Daylight Time sa Bundok", "MESZ": "Oras sa Tag-init ng Gitnang Europe", "MEZ": "Standard na Oras sa Gitnang Europe", "MST": "Standard na Oras sa Bundok", "MYT": "Oras sa Malaysia", "NZDT": "Daylight Time sa New Zealand", "NZST": "Standard na Oras sa New Zealand", "OESZ": "Oras sa Tag-init ng Silangang Europe", "OEZ": "Standard na Oras sa Silangang Europe", "PDT": "Daylight Time sa Pasipiko", "PST": "Standard na Oras sa Pasipiko", "SAST": "Oras sa Timog Africa", "SGT": "Standard na Oras sa Singapore", "SRT": "Oras sa Suriname", "TMST": "Oras sa Tag-init ng Turkmenistan", "TMT": "Standard na Oras sa Turkmenistan", "UYST": "Oras sa Tag-init ng Uruguay", "UYT": "Standard na Oras sa Uruguay", "VET": "Oras sa Venezuela", "WARST": "Oras sa Tag-init ng Kanlurang Argentina", "WART": "Standard na Oras sa Kanlurang Argentina", "WAST": "Oras sa Tag-init ng Kanlurang Africa", "WAT": "Standard na Oras sa Kanlurang Africa", "WESZ": "Oras sa Tag-init ng Kanlurang Europe", "WEZ": "Standard na Oras sa Kanlurang Europe", "WIB": "Oras sa Kanlurang Indonesia", "WIT": "Oras sa Silangang Indonesia", "WITA": "Oras sa Gitnang Indonesia", "∅∅∅": "Oras sa Tag-init ng Azores"}, 75 } 76} 77 78// Locale returns the current translators string locale 79func (fil *fil) Locale() string { 80 return fil.locale 81} 82 83// PluralsCardinal returns the list of cardinal plural rules associated with 'fil' 84func (fil *fil) PluralsCardinal() []locales.PluralRule { 85 return fil.pluralsCardinal 86} 87 88// PluralsOrdinal returns the list of ordinal plural rules associated with 'fil' 89func (fil *fil) PluralsOrdinal() []locales.PluralRule { 90 return fil.pluralsOrdinal 91} 92 93// PluralsRange returns the list of range plural rules associated with 'fil' 94func (fil *fil) PluralsRange() []locales.PluralRule { 95 return fil.pluralsRange 96} 97 98// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'fil' 99func (fil *fil) CardinalPluralRule(num float64, v uint64) locales.PluralRule { 100 101 n := math.Abs(num) 102 i := int64(n) 103 f := locales.F(n, v) 104 iMod10 := i % 10 105 fMod10 := f % 10 106 107 if (v == 0 && (i == 1 || i == 2 || i == 3)) || (v == 0 && (iMod10 != 4 && iMod10 != 6 && iMod10 != 9)) || (v != 0 && (fMod10 != 4 && fMod10 != 6 && fMod10 != 9)) { 108 return locales.PluralRuleOne 109 } 110 111 return locales.PluralRuleOther 112} 113 114// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'fil' 115func (fil *fil) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 116 117 n := math.Abs(num) 118 119 if n == 1 { 120 return locales.PluralRuleOne 121 } 122 123 return locales.PluralRuleOther 124} 125 126// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'fil' 127func (fil *fil) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 128 129 start := fil.CardinalPluralRule(num1, v1) 130 end := fil.CardinalPluralRule(num2, v2) 131 132 if start == locales.PluralRuleOne && end == locales.PluralRuleOne { 133 return locales.PluralRuleOne 134 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther { 135 return locales.PluralRuleOther 136 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne { 137 return locales.PluralRuleOne 138 } 139 140 return locales.PluralRuleOther 141 142} 143 144// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 145func (fil *fil) MonthAbbreviated(month time.Month) string { 146 return fil.monthsAbbreviated[month] 147} 148 149// MonthsAbbreviated returns the locales abbreviated months 150func (fil *fil) MonthsAbbreviated() []string { 151 return fil.monthsAbbreviated[1:] 152} 153 154// MonthNarrow returns the locales narrow month given the 'month' provided 155func (fil *fil) MonthNarrow(month time.Month) string { 156 return fil.monthsNarrow[month] 157} 158 159// MonthsNarrow returns the locales narrow months 160func (fil *fil) MonthsNarrow() []string { 161 return fil.monthsNarrow[1:] 162} 163 164// MonthWide returns the locales wide month given the 'month' provided 165func (fil *fil) MonthWide(month time.Month) string { 166 return fil.monthsWide[month] 167} 168 169// MonthsWide returns the locales wide months 170func (fil *fil) MonthsWide() []string { 171 return fil.monthsWide[1:] 172} 173 174// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 175func (fil *fil) WeekdayAbbreviated(weekday time.Weekday) string { 176 return fil.daysAbbreviated[weekday] 177} 178 179// WeekdaysAbbreviated returns the locales abbreviated weekdays 180func (fil *fil) WeekdaysAbbreviated() []string { 181 return fil.daysAbbreviated 182} 183 184// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 185func (fil *fil) WeekdayNarrow(weekday time.Weekday) string { 186 return fil.daysNarrow[weekday] 187} 188 189// WeekdaysNarrow returns the locales narrow weekdays 190func (fil *fil) WeekdaysNarrow() []string { 191 return fil.daysNarrow 192} 193 194// WeekdayShort returns the locales short weekday given the 'weekday' provided 195func (fil *fil) WeekdayShort(weekday time.Weekday) string { 196 return fil.daysShort[weekday] 197} 198 199// WeekdaysShort returns the locales short weekdays 200func (fil *fil) WeekdaysShort() []string { 201 return fil.daysShort 202} 203 204// WeekdayWide returns the locales wide weekday given the 'weekday' provided 205func (fil *fil) WeekdayWide(weekday time.Weekday) string { 206 return fil.daysWide[weekday] 207} 208 209// WeekdaysWide returns the locales wide weekdays 210func (fil *fil) WeekdaysWide() []string { 211 return fil.daysWide 212} 213 214// Decimal returns the decimal point of number 215func (fil *fil) Decimal() string { 216 return fil.decimal 217} 218 219// Group returns the group of number 220func (fil *fil) Group() string { 221 return fil.group 222} 223 224// Group returns the minus sign of number 225func (fil *fil) Minus() string { 226 return fil.minus 227} 228 229// FmtNumber returns 'num' with digits/precision of 'v' for 'fil' and handles both Whole and Real numbers based on 'v' 230func (fil *fil) FmtNumber(num float64, v uint64) string { 231 232 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 233 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3 234 count := 0 235 inWhole := v == 0 236 b := make([]byte, 0, l) 237 238 for i := len(s) - 1; i >= 0; i-- { 239 240 if s[i] == '.' { 241 b = append(b, fil.decimal[0]) 242 inWhole = true 243 continue 244 } 245 246 if inWhole { 247 if count == 3 { 248 b = append(b, fil.group[0]) 249 count = 1 250 } else { 251 count++ 252 } 253 } 254 255 b = append(b, s[i]) 256 } 257 258 if num < 0 { 259 b = append(b, fil.minus[0]) 260 } 261 262 // reverse 263 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 264 b[i], b[j] = b[j], b[i] 265 } 266 267 return string(b) 268} 269 270// FmtPercent returns 'num' with digits/precision of 'v' for 'fil' and handles both Whole and Real numbers based on 'v' 271// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 272func (fil *fil) FmtPercent(num float64, v uint64) string { 273 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 274 l := len(s) + 3 275 b := make([]byte, 0, l) 276 277 for i := len(s) - 1; i >= 0; i-- { 278 279 if s[i] == '.' { 280 b = append(b, fil.decimal[0]) 281 continue 282 } 283 284 b = append(b, s[i]) 285 } 286 287 if num < 0 { 288 b = append(b, fil.minus[0]) 289 } 290 291 // reverse 292 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 293 b[i], b[j] = b[j], b[i] 294 } 295 296 b = append(b, fil.percent...) 297 298 return string(b) 299} 300 301// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'fil' 302func (fil *fil) FmtCurrency(num float64, v uint64, currency currency.Type) string { 303 304 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 305 symbol := fil.currencies[currency] 306 l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3 307 count := 0 308 inWhole := v == 0 309 b := make([]byte, 0, l) 310 311 for i := len(s) - 1; i >= 0; i-- { 312 313 if s[i] == '.' { 314 b = append(b, fil.decimal[0]) 315 inWhole = true 316 continue 317 } 318 319 if inWhole { 320 if count == 3 { 321 b = append(b, fil.group[0]) 322 count = 1 323 } else { 324 count++ 325 } 326 } 327 328 b = append(b, s[i]) 329 } 330 331 for j := len(symbol) - 1; j >= 0; j-- { 332 b = append(b, symbol[j]) 333 } 334 335 if num < 0 { 336 b = append(b, fil.minus[0]) 337 } 338 339 // reverse 340 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 341 b[i], b[j] = b[j], b[i] 342 } 343 344 if int(v) < 2 { 345 346 if v == 0 { 347 b = append(b, fil.decimal...) 348 } 349 350 for i := 0; i < 2-int(v); i++ { 351 b = append(b, '0') 352 } 353 } 354 355 return string(b) 356} 357 358// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'fil' 359// in accounting notation. 360func (fil *fil) FmtAccounting(num float64, v uint64, currency currency.Type) string { 361 362 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 363 symbol := fil.currencies[currency] 364 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 365 count := 0 366 inWhole := v == 0 367 b := make([]byte, 0, l) 368 369 for i := len(s) - 1; i >= 0; i-- { 370 371 if s[i] == '.' { 372 b = append(b, fil.decimal[0]) 373 inWhole = true 374 continue 375 } 376 377 if inWhole { 378 if count == 3 { 379 b = append(b, fil.group[0]) 380 count = 1 381 } else { 382 count++ 383 } 384 } 385 386 b = append(b, s[i]) 387 } 388 389 if num < 0 { 390 391 for j := len(symbol) - 1; j >= 0; j-- { 392 b = append(b, symbol[j]) 393 } 394 395 b = append(b, fil.currencyNegativePrefix[0]) 396 397 } else { 398 399 for j := len(symbol) - 1; j >= 0; j-- { 400 b = append(b, symbol[j]) 401 } 402 403 } 404 405 // reverse 406 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 407 b[i], b[j] = b[j], b[i] 408 } 409 410 if int(v) < 2 { 411 412 if v == 0 { 413 b = append(b, fil.decimal...) 414 } 415 416 for i := 0; i < 2-int(v); i++ { 417 b = append(b, '0') 418 } 419 } 420 421 if num < 0 { 422 b = append(b, fil.currencyNegativeSuffix...) 423 } 424 425 return string(b) 426} 427 428// FmtDateShort returns the short date representation of 't' for 'fil' 429func (fil *fil) FmtDateShort(t time.Time) string { 430 431 b := make([]byte, 0, 32) 432 433 b = strconv.AppendInt(b, int64(t.Month()), 10) 434 b = append(b, []byte{0x2f}...) 435 b = strconv.AppendInt(b, int64(t.Day()), 10) 436 b = append(b, []byte{0x2f}...) 437 438 if t.Year() > 9 { 439 b = append(b, strconv.Itoa(t.Year())[2:]...) 440 } else { 441 b = append(b, strconv.Itoa(t.Year())[1:]...) 442 } 443 444 return string(b) 445} 446 447// FmtDateMedium returns the medium date representation of 't' for 'fil' 448func (fil *fil) FmtDateMedium(t time.Time) string { 449 450 b := make([]byte, 0, 32) 451 452 b = append(b, fil.monthsAbbreviated[t.Month()]...) 453 b = append(b, []byte{0x20}...) 454 b = strconv.AppendInt(b, int64(t.Day()), 10) 455 b = append(b, []byte{0x2c, 0x20}...) 456 457 if t.Year() > 0 { 458 b = strconv.AppendInt(b, int64(t.Year()), 10) 459 } else { 460 b = strconv.AppendInt(b, int64(-t.Year()), 10) 461 } 462 463 return string(b) 464} 465 466// FmtDateLong returns the long date representation of 't' for 'fil' 467func (fil *fil) FmtDateLong(t time.Time) string { 468 469 b := make([]byte, 0, 32) 470 471 b = append(b, fil.monthsWide[t.Month()]...) 472 b = append(b, []byte{0x20}...) 473 b = strconv.AppendInt(b, int64(t.Day()), 10) 474 b = append(b, []byte{0x2c, 0x20}...) 475 476 if t.Year() > 0 { 477 b = strconv.AppendInt(b, int64(t.Year()), 10) 478 } else { 479 b = strconv.AppendInt(b, int64(-t.Year()), 10) 480 } 481 482 return string(b) 483} 484 485// FmtDateFull returns the full date representation of 't' for 'fil' 486func (fil *fil) FmtDateFull(t time.Time) string { 487 488 b := make([]byte, 0, 32) 489 490 b = append(b, fil.daysWide[t.Weekday()]...) 491 b = append(b, []byte{0x2c, 0x20}...) 492 b = append(b, fil.monthsWide[t.Month()]...) 493 b = append(b, []byte{0x20}...) 494 b = strconv.AppendInt(b, int64(t.Day()), 10) 495 b = append(b, []byte{0x2c, 0x20}...) 496 497 if t.Year() > 0 { 498 b = strconv.AppendInt(b, int64(t.Year()), 10) 499 } else { 500 b = strconv.AppendInt(b, int64(-t.Year()), 10) 501 } 502 503 return string(b) 504} 505 506// FmtTimeShort returns the short time representation of 't' for 'fil' 507func (fil *fil) FmtTimeShort(t time.Time) string { 508 509 b := make([]byte, 0, 32) 510 511 h := t.Hour() 512 513 if h > 12 { 514 h -= 12 515 } 516 517 b = strconv.AppendInt(b, int64(h), 10) 518 b = append(b, fil.timeSeparator...) 519 520 if t.Minute() < 10 { 521 b = append(b, '0') 522 } 523 524 b = strconv.AppendInt(b, int64(t.Minute()), 10) 525 b = append(b, []byte{0x20}...) 526 527 if t.Hour() < 12 { 528 b = append(b, fil.periodsAbbreviated[0]...) 529 } else { 530 b = append(b, fil.periodsAbbreviated[1]...) 531 } 532 533 return string(b) 534} 535 536// FmtTimeMedium returns the medium time representation of 't' for 'fil' 537func (fil *fil) FmtTimeMedium(t time.Time) string { 538 539 b := make([]byte, 0, 32) 540 541 h := t.Hour() 542 543 if h > 12 { 544 h -= 12 545 } 546 547 b = strconv.AppendInt(b, int64(h), 10) 548 b = append(b, fil.timeSeparator...) 549 550 if t.Minute() < 10 { 551 b = append(b, '0') 552 } 553 554 b = strconv.AppendInt(b, int64(t.Minute()), 10) 555 b = append(b, fil.timeSeparator...) 556 557 if t.Second() < 10 { 558 b = append(b, '0') 559 } 560 561 b = strconv.AppendInt(b, int64(t.Second()), 10) 562 b = append(b, []byte{0x20}...) 563 564 if t.Hour() < 12 { 565 b = append(b, fil.periodsAbbreviated[0]...) 566 } else { 567 b = append(b, fil.periodsAbbreviated[1]...) 568 } 569 570 return string(b) 571} 572 573// FmtTimeLong returns the long time representation of 't' for 'fil' 574func (fil *fil) FmtTimeLong(t time.Time) string { 575 576 b := make([]byte, 0, 32) 577 578 h := t.Hour() 579 580 if h > 12 { 581 h -= 12 582 } 583 584 b = strconv.AppendInt(b, int64(h), 10) 585 b = append(b, fil.timeSeparator...) 586 587 if t.Minute() < 10 { 588 b = append(b, '0') 589 } 590 591 b = strconv.AppendInt(b, int64(t.Minute()), 10) 592 b = append(b, fil.timeSeparator...) 593 594 if t.Second() < 10 { 595 b = append(b, '0') 596 } 597 598 b = strconv.AppendInt(b, int64(t.Second()), 10) 599 b = append(b, []byte{0x20}...) 600 601 if t.Hour() < 12 { 602 b = append(b, fil.periodsAbbreviated[0]...) 603 } else { 604 b = append(b, fil.periodsAbbreviated[1]...) 605 } 606 607 b = append(b, []byte{0x20}...) 608 609 tz, _ := t.Zone() 610 b = append(b, tz...) 611 612 return string(b) 613} 614 615// FmtTimeFull returns the full time representation of 't' for 'fil' 616func (fil *fil) FmtTimeFull(t time.Time) string { 617 618 b := make([]byte, 0, 32) 619 620 h := t.Hour() 621 622 if h > 12 { 623 h -= 12 624 } 625 626 b = strconv.AppendInt(b, int64(h), 10) 627 b = append(b, fil.timeSeparator...) 628 629 if t.Minute() < 10 { 630 b = append(b, '0') 631 } 632 633 b = strconv.AppendInt(b, int64(t.Minute()), 10) 634 b = append(b, fil.timeSeparator...) 635 636 if t.Second() < 10 { 637 b = append(b, '0') 638 } 639 640 b = strconv.AppendInt(b, int64(t.Second()), 10) 641 b = append(b, []byte{0x20}...) 642 643 if t.Hour() < 12 { 644 b = append(b, fil.periodsAbbreviated[0]...) 645 } else { 646 b = append(b, fil.periodsAbbreviated[1]...) 647 } 648 649 b = append(b, []byte{0x20}...) 650 651 tz, _ := t.Zone() 652 653 if btz, ok := fil.timezones[tz]; ok { 654 b = append(b, btz...) 655 } else { 656 b = append(b, tz...) 657 } 658 659 return string(b) 660} 661