1package de 2 3import ( 4 "math" 5 "strconv" 6 "time" 7 8 "github.com/go-playground/locales" 9 "github.com/go-playground/locales/currency" 10) 11 12type de 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 'de' locale 46func New() locales.Translator { 47 return &de{ 48 locale: "de", 49 pluralsCardinal: []locales.PluralRule{2, 6}, 50 pluralsOrdinal: []locales.PluralRule{6}, 51 pluralsRange: []locales.PluralRule{2, 6}, 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", "BGK", "BGN", "BGJ", "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", "DM", "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", "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", "UZS", "VEB", "VEF", "₫", "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ärz", "Apr.", "Mai", "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ärz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"}, 66 daysAbbreviated: []string{"So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa."}, 67 daysNarrow: []string{"S", "M", "D", "M", "D", "F", "S"}, 68 daysShort: []string{"So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa."}, 69 daysWide: []string{"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"}, 70 periodsAbbreviated: []string{"vorm.", "nachm."}, 71 periodsNarrow: []string{"vm.", "nm."}, 72 periodsWide: []string{"vorm.", "nachm."}, 73 erasAbbreviated: []string{"v. Chr.", "n. Chr."}, 74 erasNarrow: []string{"v. Chr.", "n. Chr."}, 75 erasWide: []string{"v. Chr.", "n. Chr."}, 76 timezones: map[string]string{"HEOG": "Westgrönland-Sommerzeit", "CLT": "Chilenische Normalzeit", "HNPMX": "Mexiko Pazifikzone-Normalzeit", "MYT": "Malaysische Zeit", "MEZ": "Mitteleuropäische Normalzeit", "LHST": "Lord-Howe-Normalzeit", "SRT": "Suriname-Zeit", "ARST": "Argentinische Sommerzeit", "GMT": "Mittlere Greenwich-Zeit", "SAST": "Südafrikanische Zeit", "ECT": "Ecuadorianische Zeit", "ACST": "Zentralaustralische Normalzeit", "HNNOMX": "Mexiko Nordwestliche Zone-Normalzeit", "CLST": "Chilenische Sommerzeit", "CST": "Nordamerikanische Inland-Normalzeit", "BOT": "Bolivianische Zeit", "WITA": "Zentralindonesische Zeit", "CDT": "Nordamerikanische Inland-Sommerzeit", "AEDT": "Ostaustralische Sommerzeit", "AKDT": "Alaska-Sommerzeit", "HNPM": "Saint-Pierre-und-Miquelon-Normalzeit", "UYST": "Uruguayanische Sommerzeit", "HECU": "Kubanische Sommerzeit", "UYT": "Uruguyanische Normalzeit", "PDT": "Nordamerikanische Westküsten-Sommerzeit", "GFT": "Französisch-Guayana-Zeit", "MESZ": "Mitteleuropäische Sommerzeit", "HKT": "Hongkong-Normalzeit", "WARST": "Westargentinische Sommerzeit", "VET": "Venezuela-Zeit", "TMT": "Turkmenistan-Normalzeit", "HNCU": "Kubanische Normalzeit", "HEPMX": "Mexiko Pazifikzone-Sommerzeit", "PST": "Nordamerikanische Westküsten-Normalzeit", "ADT": "Atlantik-Sommerzeit", "ACDT": "Zentralaustralische Sommerzeit", "CAT": "Zentralafrikanische Zeit", "HAST": "Hawaii-Aleuten-Normalzeit", "CHAST": "Chatham-Normalzeit", "WAST": "Westafrikanische Sommerzeit", "WESZ": "Westeuropäische Sommerzeit", "WART": "Westargentinische Normalzeit", "HNT": "Neufundland-Normalzeit", "WIB": "Westindonesische Zeit", "NZST": "Neuseeland-Normalzeit", "HEPM": "Saint-Pierre-und-Miquelon-Sommerzeit", "WIT": "Ostindonesische Zeit", "MDT": "Rocky-Mountain-Sommerzeit", "AKST": "Alaska-Normalzeit", "SGT": "Singapur-Zeit", "COST": "Kolumbianische Sommerzeit", "CHADT": "Chatham-Sommerzeit", "GYT": "Guyana-Zeit", "AWDT": "Westaustralische Sommerzeit", "∅∅∅": "Acre-Sommerzeit", "HNOG": "Westgrönland-Normalzeit", "EST": "Nordamerikanische Ostküsten-Normalzeit", "IST": "Indische Zeit", "OEZ": "Osteuropäische Normalzeit", "HADT": "Hawaii-Aleuten-Sommerzeit", "AWST": "Westaustralische Normalzeit", "WAT": "Westafrikanische Normalzeit", "WEZ": "Westeuropäische Normalzeit", "HEEG": "Ostgrönland-Sommerzeit", "ACWST": "Zentral-/Westaustralische Normalzeit", "LHDT": "Lord-Howe-Sommerzeit", "EAT": "Ostafrikanische Zeit", "BT": "Bhutan-Zeit", "ACWDT": "Zentral-/Westaustralische Sommerzeit", "HENOMX": "Mexiko Nordwestliche Zone-Sommerzeit", "COT": "Kolumbianische Normalzeit", "OESZ": "Osteuropäische Sommerzeit", "ChST": "Chamorro-Zeit", "AEST": "Ostaustralische Normalzeit", "NZDT": "Neuseeland-Sommerzeit", "EDT": "Nordamerikanische Ostküsten-Sommerzeit", "TMST": "Turkmenistan-Sommerzeit", "MST": "Rocky Mountain-Normalzeit", "HNEG": "Ostgrönland-Normalzeit", "AST": "Atlantik-Normalzeit", "JST": "Japanische Normalzeit", "JDT": "Japanische Sommerzeit", "HKST": "Hongkong-Sommerzeit", "HAT": "Neufundland-Sommerzeit", "ART": "Argentinische Normalzeit"}, 77 } 78} 79 80// Locale returns the current translators string locale 81func (de *de) Locale() string { 82 return de.locale 83} 84 85// PluralsCardinal returns the list of cardinal plural rules associated with 'de' 86func (de *de) PluralsCardinal() []locales.PluralRule { 87 return de.pluralsCardinal 88} 89 90// PluralsOrdinal returns the list of ordinal plural rules associated with 'de' 91func (de *de) PluralsOrdinal() []locales.PluralRule { 92 return de.pluralsOrdinal 93} 94 95// PluralsRange returns the list of range plural rules associated with 'de' 96func (de *de) PluralsRange() []locales.PluralRule { 97 return de.pluralsRange 98} 99 100// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'de' 101func (de *de) CardinalPluralRule(num float64, v uint64) locales.PluralRule { 102 103 n := math.Abs(num) 104 i := int64(n) 105 106 if i == 1 && v == 0 { 107 return locales.PluralRuleOne 108 } 109 110 return locales.PluralRuleOther 111} 112 113// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'de' 114func (de *de) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 115 return locales.PluralRuleOther 116} 117 118// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'de' 119func (de *de) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 120 121 start := de.CardinalPluralRule(num1, v1) 122 end := de.CardinalPluralRule(num2, v2) 123 124 if start == locales.PluralRuleOne && end == locales.PluralRuleOther { 125 return locales.PluralRuleOther 126 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne { 127 return locales.PluralRuleOne 128 } 129 130 return locales.PluralRuleOther 131 132} 133 134// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 135func (de *de) MonthAbbreviated(month time.Month) string { 136 return de.monthsAbbreviated[month] 137} 138 139// MonthsAbbreviated returns the locales abbreviated months 140func (de *de) MonthsAbbreviated() []string { 141 return de.monthsAbbreviated[1:] 142} 143 144// MonthNarrow returns the locales narrow month given the 'month' provided 145func (de *de) MonthNarrow(month time.Month) string { 146 return de.monthsNarrow[month] 147} 148 149// MonthsNarrow returns the locales narrow months 150func (de *de) MonthsNarrow() []string { 151 return de.monthsNarrow[1:] 152} 153 154// MonthWide returns the locales wide month given the 'month' provided 155func (de *de) MonthWide(month time.Month) string { 156 return de.monthsWide[month] 157} 158 159// MonthsWide returns the locales wide months 160func (de *de) MonthsWide() []string { 161 return de.monthsWide[1:] 162} 163 164// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 165func (de *de) WeekdayAbbreviated(weekday time.Weekday) string { 166 return de.daysAbbreviated[weekday] 167} 168 169// WeekdaysAbbreviated returns the locales abbreviated weekdays 170func (de *de) WeekdaysAbbreviated() []string { 171 return de.daysAbbreviated 172} 173 174// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 175func (de *de) WeekdayNarrow(weekday time.Weekday) string { 176 return de.daysNarrow[weekday] 177} 178 179// WeekdaysNarrow returns the locales narrow weekdays 180func (de *de) WeekdaysNarrow() []string { 181 return de.daysNarrow 182} 183 184// WeekdayShort returns the locales short weekday given the 'weekday' provided 185func (de *de) WeekdayShort(weekday time.Weekday) string { 186 return de.daysShort[weekday] 187} 188 189// WeekdaysShort returns the locales short weekdays 190func (de *de) WeekdaysShort() []string { 191 return de.daysShort 192} 193 194// WeekdayWide returns the locales wide weekday given the 'weekday' provided 195func (de *de) WeekdayWide(weekday time.Weekday) string { 196 return de.daysWide[weekday] 197} 198 199// WeekdaysWide returns the locales wide weekdays 200func (de *de) WeekdaysWide() []string { 201 return de.daysWide 202} 203 204// Decimal returns the decimal point of number 205func (de *de) Decimal() string { 206 return de.decimal 207} 208 209// Group returns the group of number 210func (de *de) Group() string { 211 return de.group 212} 213 214// Group returns the minus sign of number 215func (de *de) Minus() string { 216 return de.minus 217} 218 219// FmtNumber returns 'num' with digits/precision of 'v' for 'de' and handles both Whole and Real numbers based on 'v' 220func (de *de) FmtNumber(num float64, v uint64) string { 221 222 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 223 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3 224 count := 0 225 inWhole := v == 0 226 b := make([]byte, 0, l) 227 228 for i := len(s) - 1; i >= 0; i-- { 229 230 if s[i] == '.' { 231 b = append(b, de.decimal[0]) 232 inWhole = true 233 continue 234 } 235 236 if inWhole { 237 if count == 3 { 238 b = append(b, de.group[0]) 239 count = 1 240 } else { 241 count++ 242 } 243 } 244 245 b = append(b, s[i]) 246 } 247 248 if num < 0 { 249 b = append(b, de.minus[0]) 250 } 251 252 // reverse 253 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 254 b[i], b[j] = b[j], b[i] 255 } 256 257 return string(b) 258} 259 260// FmtPercent returns 'num' with digits/precision of 'v' for 'de' and handles both Whole and Real numbers based on 'v' 261// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 262func (de *de) FmtPercent(num float64, v uint64) string { 263 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 264 l := len(s) + 5 265 b := make([]byte, 0, l) 266 267 for i := len(s) - 1; i >= 0; i-- { 268 269 if s[i] == '.' { 270 b = append(b, de.decimal[0]) 271 continue 272 } 273 274 b = append(b, s[i]) 275 } 276 277 if num < 0 { 278 b = append(b, de.minus[0]) 279 } 280 281 // reverse 282 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 283 b[i], b[j] = b[j], b[i] 284 } 285 286 b = append(b, de.percentSuffix...) 287 288 b = append(b, de.percent...) 289 290 return string(b) 291} 292 293// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'de' 294func (de *de) FmtCurrency(num float64, v uint64, currency currency.Type) string { 295 296 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 297 symbol := de.currencies[currency] 298 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 299 count := 0 300 inWhole := v == 0 301 b := make([]byte, 0, l) 302 303 for i := len(s) - 1; i >= 0; i-- { 304 305 if s[i] == '.' { 306 b = append(b, de.decimal[0]) 307 inWhole = true 308 continue 309 } 310 311 if inWhole { 312 if count == 3 { 313 b = append(b, de.group[0]) 314 count = 1 315 } else { 316 count++ 317 } 318 } 319 320 b = append(b, s[i]) 321 } 322 323 if num < 0 { 324 b = append(b, de.minus[0]) 325 } 326 327 // reverse 328 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 329 b[i], b[j] = b[j], b[i] 330 } 331 332 if int(v) < 2 { 333 334 if v == 0 { 335 b = append(b, de.decimal...) 336 } 337 338 for i := 0; i < 2-int(v); i++ { 339 b = append(b, '0') 340 } 341 } 342 343 b = append(b, de.currencyPositiveSuffix...) 344 345 b = append(b, symbol...) 346 347 return string(b) 348} 349 350// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'de' 351// in accounting notation. 352func (de *de) FmtAccounting(num float64, v uint64, currency currency.Type) string { 353 354 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 355 symbol := de.currencies[currency] 356 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 357 count := 0 358 inWhole := v == 0 359 b := make([]byte, 0, l) 360 361 for i := len(s) - 1; i >= 0; i-- { 362 363 if s[i] == '.' { 364 b = append(b, de.decimal[0]) 365 inWhole = true 366 continue 367 } 368 369 if inWhole { 370 if count == 3 { 371 b = append(b, de.group[0]) 372 count = 1 373 } else { 374 count++ 375 } 376 } 377 378 b = append(b, s[i]) 379 } 380 381 if num < 0 { 382 383 b = append(b, de.minus[0]) 384 385 } 386 387 // reverse 388 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 389 b[i], b[j] = b[j], b[i] 390 } 391 392 if int(v) < 2 { 393 394 if v == 0 { 395 b = append(b, de.decimal...) 396 } 397 398 for i := 0; i < 2-int(v); i++ { 399 b = append(b, '0') 400 } 401 } 402 403 if num < 0 { 404 b = append(b, de.currencyNegativeSuffix...) 405 b = append(b, symbol...) 406 } else { 407 408 b = append(b, de.currencyPositiveSuffix...) 409 b = append(b, symbol...) 410 } 411 412 return string(b) 413} 414 415// FmtDateShort returns the short date representation of 't' for 'de' 416func (de *de) FmtDateShort(t time.Time) string { 417 418 b := make([]byte, 0, 32) 419 420 if t.Day() < 10 { 421 b = append(b, '0') 422 } 423 424 b = strconv.AppendInt(b, int64(t.Day()), 10) 425 b = append(b, []byte{0x2e}...) 426 427 if t.Month() < 10 { 428 b = append(b, '0') 429 } 430 431 b = strconv.AppendInt(b, int64(t.Month()), 10) 432 433 b = append(b, []byte{0x2e}...) 434 435 if t.Year() > 9 { 436 b = append(b, strconv.Itoa(t.Year())[2:]...) 437 } else { 438 b = append(b, strconv.Itoa(t.Year())[1:]...) 439 } 440 441 return string(b) 442} 443 444// FmtDateMedium returns the medium date representation of 't' for 'de' 445func (de *de) FmtDateMedium(t time.Time) string { 446 447 b := make([]byte, 0, 32) 448 449 if t.Day() < 10 { 450 b = append(b, '0') 451 } 452 453 b = strconv.AppendInt(b, int64(t.Day()), 10) 454 b = append(b, []byte{0x2e}...) 455 456 if t.Month() < 10 { 457 b = append(b, '0') 458 } 459 460 b = strconv.AppendInt(b, int64(t.Month()), 10) 461 462 b = append(b, []byte{0x2e}...) 463 464 if t.Year() > 0 { 465 b = strconv.AppendInt(b, int64(t.Year()), 10) 466 } else { 467 b = strconv.AppendInt(b, int64(-t.Year()), 10) 468 } 469 470 return string(b) 471} 472 473// FmtDateLong returns the long date representation of 't' for 'de' 474func (de *de) FmtDateLong(t time.Time) string { 475 476 b := make([]byte, 0, 32) 477 478 b = strconv.AppendInt(b, int64(t.Day()), 10) 479 b = append(b, []byte{0x2e, 0x20}...) 480 b = append(b, de.monthsWide[t.Month()]...) 481 b = append(b, []byte{0x20}...) 482 483 if t.Year() > 0 { 484 b = strconv.AppendInt(b, int64(t.Year()), 10) 485 } else { 486 b = strconv.AppendInt(b, int64(-t.Year()), 10) 487 } 488 489 return string(b) 490} 491 492// FmtDateFull returns the full date representation of 't' for 'de' 493func (de *de) FmtDateFull(t time.Time) string { 494 495 b := make([]byte, 0, 32) 496 497 b = append(b, de.daysWide[t.Weekday()]...) 498 b = append(b, []byte{0x2c, 0x20}...) 499 b = strconv.AppendInt(b, int64(t.Day()), 10) 500 b = append(b, []byte{0x2e, 0x20}...) 501 b = append(b, de.monthsWide[t.Month()]...) 502 b = append(b, []byte{0x20}...) 503 504 if t.Year() > 0 { 505 b = strconv.AppendInt(b, int64(t.Year()), 10) 506 } else { 507 b = strconv.AppendInt(b, int64(-t.Year()), 10) 508 } 509 510 return string(b) 511} 512 513// FmtTimeShort returns the short time representation of 't' for 'de' 514func (de *de) FmtTimeShort(t time.Time) string { 515 516 b := make([]byte, 0, 32) 517 518 if t.Hour() < 10 { 519 b = append(b, '0') 520 } 521 522 b = strconv.AppendInt(b, int64(t.Hour()), 10) 523 b = append(b, de.timeSeparator...) 524 525 if t.Minute() < 10 { 526 b = append(b, '0') 527 } 528 529 b = strconv.AppendInt(b, int64(t.Minute()), 10) 530 531 return string(b) 532} 533 534// FmtTimeMedium returns the medium time representation of 't' for 'de' 535func (de *de) FmtTimeMedium(t time.Time) string { 536 537 b := make([]byte, 0, 32) 538 539 if t.Hour() < 10 { 540 b = append(b, '0') 541 } 542 543 b = strconv.AppendInt(b, int64(t.Hour()), 10) 544 b = append(b, de.timeSeparator...) 545 546 if t.Minute() < 10 { 547 b = append(b, '0') 548 } 549 550 b = strconv.AppendInt(b, int64(t.Minute()), 10) 551 b = append(b, de.timeSeparator...) 552 553 if t.Second() < 10 { 554 b = append(b, '0') 555 } 556 557 b = strconv.AppendInt(b, int64(t.Second()), 10) 558 559 return string(b) 560} 561 562// FmtTimeLong returns the long time representation of 't' for 'de' 563func (de *de) FmtTimeLong(t time.Time) string { 564 565 b := make([]byte, 0, 32) 566 567 if t.Hour() < 10 { 568 b = append(b, '0') 569 } 570 571 b = strconv.AppendInt(b, int64(t.Hour()), 10) 572 b = append(b, de.timeSeparator...) 573 574 if t.Minute() < 10 { 575 b = append(b, '0') 576 } 577 578 b = strconv.AppendInt(b, int64(t.Minute()), 10) 579 b = append(b, de.timeSeparator...) 580 581 if t.Second() < 10 { 582 b = append(b, '0') 583 } 584 585 b = strconv.AppendInt(b, int64(t.Second()), 10) 586 b = append(b, []byte{0x20}...) 587 588 tz, _ := t.Zone() 589 b = append(b, tz...) 590 591 return string(b) 592} 593 594// FmtTimeFull returns the full time representation of 't' for 'de' 595func (de *de) FmtTimeFull(t time.Time) string { 596 597 b := make([]byte, 0, 32) 598 599 if t.Hour() < 10 { 600 b = append(b, '0') 601 } 602 603 b = strconv.AppendInt(b, int64(t.Hour()), 10) 604 b = append(b, de.timeSeparator...) 605 606 if t.Minute() < 10 { 607 b = append(b, '0') 608 } 609 610 b = strconv.AppendInt(b, int64(t.Minute()), 10) 611 b = append(b, de.timeSeparator...) 612 613 if t.Second() < 10 { 614 b = append(b, '0') 615 } 616 617 b = strconv.AppendInt(b, int64(t.Second()), 10) 618 b = append(b, []byte{0x20}...) 619 620 tz, _ := t.Zone() 621 622 if btz, ok := de.timezones[tz]; ok { 623 b = append(b, btz...) 624 } else { 625 b = append(b, tz...) 626 } 627 628 return string(b) 629} 630