1package hr 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 hr 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 currencyPositiveSuffix 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 'hr' locale 45func New() locales.Translator { 46 return &hr{ 47 locale: "hr", 48 pluralsCardinal: []locales.PluralRule{2, 4, 6}, 49 pluralsOrdinal: []locales.PluralRule{6}, 50 pluralsRange: []locales.PluralRule{2, 4, 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", "AUD", "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", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "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", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "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", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZD", "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", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"}, 59 currencyPositiveSuffix: " ", 60 currencyNegativeSuffix: " ", 61 monthsAbbreviated: []string{"", "sij", "velj", "ožu", "tra", "svi", "lip", "srp", "kol", "ruj", "lis", "stu", "pro"}, 62 monthsNarrow: []string{"", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12."}, 63 monthsWide: []string{"", "siječnja", "veljače", "ožujka", "travnja", "svibnja", "lipnja", "srpnja", "kolovoza", "rujna", "listopada", "studenoga", "prosinca"}, 64 daysAbbreviated: []string{"ned", "pon", "uto", "sri", "čet", "pet", "sub"}, 65 daysNarrow: []string{"N", "P", "U", "S", "Č", "P", "S"}, 66 daysShort: []string{"ned", "pon", "uto", "sri", "čet", "pet", "sub"}, 67 daysWide: []string{"nedjelja", "ponedjeljak", "utorak", "srijeda", "četvrtak", "petak", "subota"}, 68 periodsAbbreviated: []string{"AM", "PM"}, 69 periodsNarrow: []string{"AM", "PM"}, 70 periodsWide: []string{"AM", "PM"}, 71 erasAbbreviated: []string{"pr. Kr.", "po. Kr."}, 72 erasNarrow: []string{"pr.n.e.", "AD"}, 73 erasWide: []string{"prije Krista", "poslije Krista"}, 74 timezones: map[string]string{"ADT": "atlantsko ljetno vrijeme", "SRT": "surinamsko vrijeme", "TMST": "turkmenistansko ljetno vrijeme", "PDT": "pacifičko ljetno vrijeme", "WIT": "istočnoindonezijsko vrijeme", "UYT": "urugvajsko standardno vrijeme", "PST": "pacifičko standardno vrijeme", "WEZ": "zapadnoeuropsko standardno vrijeme", "WARST": "zapadnoargentinsko ljetno vrijeme", "MST": "standardno makaosko vrijeme", "TMT": "turkmenistansko standardno vrijeme", "OEZ": "istočnoeuropsko standardno vrijeme", "GMT": "univerzalno vrijeme", "AWST": "zapadnoaustralsko standardno vrijeme", "JST": "japansko standardno vrijeme", "VET": "venezuelsko vrijeme", "EAT": "istočnoafričko vrijeme", "HNPMX": "meksičko pacifičko standardno vrijeme", "HNEG": "istočnogrenlandsko standardno vrijeme", "CAT": "srednjoafričko vrijeme", "GYT": "gvajansko vrijeme", "HEPM": "ljetno vrijeme za Sveti Petar i Mikelon", "HENOMX": "sjeverozapadno meksičko ljetno vrijeme", "CHAST": "standardno vrijeme Chathama", "CST": "središnje standardno vrijeme", "AEST": "istočnoaustralsko standardno vrijeme", "HEOG": "zapadnogrenlandsko ljetno vrijeme", "HKST": "hongkonško ljetno vrijeme", "LHST": "standardno vrijeme otoka Lord Howe", "GFT": "vrijeme Francuske Gvajane", "AKST": "aljaško standardno vrijeme", "EDT": "istočno ljetno vrijeme", "HNNOMX": "sjeverozapadno meksičko standardno vrijeme", "UYST": "urugvajsko ljetno vrijeme", "WAST": "zapadnoafričko ljetno vrijeme", "WIB": "zapadnoindonezijsko vrijeme", "BT": "butansko vrijeme", "CHADT": "ljetno vrijeme Chathama", "HNCU": "kubansko standardno vrijeme", "HKT": "hongkonško standardno vrijeme", "ARST": "argentinsko ljetno vrijeme", "WESZ": "zapadnoeuropsko ljetno vrijeme", "HEEG": "istočnogrenlandsko ljetno vrijeme", "MESZ": "srednjoeuropsko ljetno vrijeme", "CLST": "čileansko ljetno vrijeme", "HADT": "havajsko-aleutsko ljetno vrijeme", "CDT": "središnje ljetno vrijeme", "BOT": "bolivijsko vrijeme", "JDT": "japansko ljetno vrijeme", "ACWST": "australsko središnje zapadno standardno vrijeme", "HNPM": "standardno vrijeme za Sveti Petar i Mikelon", "ART": "argentinsko standardno vrijeme", "COST": "kolumbijsko ljetno vrijeme", "AEDT": "istočnoaustralsko ljetno vrijeme", "ACWDT": "australsko središnje zapadno ljetno vrijeme", "LHDT": "ljetno vrijeme otoka Lord Howe", "HAT": "newfoundlandsko ljetno vrijeme", "OESZ": "istočnoeuropsko ljetno vrijeme", "WAT": "zapadnoafričko standardno vrijeme", "SGT": "singapursko vrijeme", "WART": "zapadnoargentinsko standardno vrijeme", "IST": "indijsko vrijeme", "SAST": "južnoafričko vrijeme", "ACDT": "srednjoaustralsko ljetno vrijeme", "MEZ": "srednjoeuropsko standardno vrijeme", "HNOG": "zapadnogrenlandsko standardno vrijeme", "CLT": "čileansko standardno vrijeme", "HAST": "havajsko-aleutsko standardno vrijeme", "ChST": "standardno vrijeme Chamorra", "NZST": "novozelandsko standardno vrijeme", "MYT": "malezijsko vrijeme", "ECT": "ekvadorsko vrijeme", "WITA": "srednjoindonezijsko vrijeme", "MDT": "ljetno makaosko vrijeme", "AST": "atlantsko standardno vrijeme", "HECU": "kubansko ljetno vrijeme", "∅∅∅": "Acre ljetno vrijeme", "NZDT": "novozelandsko ljetno vrijeme", "COT": "kolumbijsko standardno vrijeme", "HNT": "newfoundlandsko standardno vrijeme", "AWDT": "zapadnoaustralsko ljetno vrijeme", "HEPMX": "meksičko pacifičko ljetno vrijeme", "AKDT": "aljaško ljetno vrijeme", "EST": "istočno standardno vrijeme", "ACST": "srednjoaustralsko standardno vrijeme"}, 75 } 76} 77 78// Locale returns the current translators string locale 79func (hr *hr) Locale() string { 80 return hr.locale 81} 82 83// PluralsCardinal returns the list of cardinal plural rules associated with 'hr' 84func (hr *hr) PluralsCardinal() []locales.PluralRule { 85 return hr.pluralsCardinal 86} 87 88// PluralsOrdinal returns the list of ordinal plural rules associated with 'hr' 89func (hr *hr) PluralsOrdinal() []locales.PluralRule { 90 return hr.pluralsOrdinal 91} 92 93// PluralsRange returns the list of range plural rules associated with 'hr' 94func (hr *hr) PluralsRange() []locales.PluralRule { 95 return hr.pluralsRange 96} 97 98// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'hr' 99func (hr *hr) 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 iMod100 := i % 100 106 fMod10 := f % 10 107 fMod100 := f % 100 108 109 if (v == 0 && iMod10 == 1 && iMod100 != 11) || (fMod10 == 1 && fMod100 != 11) { 110 return locales.PluralRuleOne 111 } else if (v == 0 && iMod10 >= 2 && iMod10 <= 4 && (iMod100 < 12 || iMod100 > 14)) || (fMod10 >= 2 && fMod10 <= 4 && (fMod100 < 12 || fMod100 > 14)) { 112 return locales.PluralRuleFew 113 } 114 115 return locales.PluralRuleOther 116} 117 118// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'hr' 119func (hr *hr) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 120 return locales.PluralRuleOther 121} 122 123// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'hr' 124func (hr *hr) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 125 126 start := hr.CardinalPluralRule(num1, v1) 127 end := hr.CardinalPluralRule(num2, v2) 128 129 if start == locales.PluralRuleOne && end == locales.PluralRuleOne { 130 return locales.PluralRuleOne 131 } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew { 132 return locales.PluralRuleFew 133 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther { 134 return locales.PluralRuleOther 135 } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne { 136 return locales.PluralRuleOne 137 } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew { 138 return locales.PluralRuleFew 139 } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther { 140 return locales.PluralRuleOther 141 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne { 142 return locales.PluralRuleOne 143 } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew { 144 return locales.PluralRuleFew 145 } 146 147 return locales.PluralRuleOther 148 149} 150 151// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 152func (hr *hr) MonthAbbreviated(month time.Month) string { 153 return hr.monthsAbbreviated[month] 154} 155 156// MonthsAbbreviated returns the locales abbreviated months 157func (hr *hr) MonthsAbbreviated() []string { 158 return hr.monthsAbbreviated[1:] 159} 160 161// MonthNarrow returns the locales narrow month given the 'month' provided 162func (hr *hr) MonthNarrow(month time.Month) string { 163 return hr.monthsNarrow[month] 164} 165 166// MonthsNarrow returns the locales narrow months 167func (hr *hr) MonthsNarrow() []string { 168 return hr.monthsNarrow[1:] 169} 170 171// MonthWide returns the locales wide month given the 'month' provided 172func (hr *hr) MonthWide(month time.Month) string { 173 return hr.monthsWide[month] 174} 175 176// MonthsWide returns the locales wide months 177func (hr *hr) MonthsWide() []string { 178 return hr.monthsWide[1:] 179} 180 181// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 182func (hr *hr) WeekdayAbbreviated(weekday time.Weekday) string { 183 return hr.daysAbbreviated[weekday] 184} 185 186// WeekdaysAbbreviated returns the locales abbreviated weekdays 187func (hr *hr) WeekdaysAbbreviated() []string { 188 return hr.daysAbbreviated 189} 190 191// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 192func (hr *hr) WeekdayNarrow(weekday time.Weekday) string { 193 return hr.daysNarrow[weekday] 194} 195 196// WeekdaysNarrow returns the locales narrow weekdays 197func (hr *hr) WeekdaysNarrow() []string { 198 return hr.daysNarrow 199} 200 201// WeekdayShort returns the locales short weekday given the 'weekday' provided 202func (hr *hr) WeekdayShort(weekday time.Weekday) string { 203 return hr.daysShort[weekday] 204} 205 206// WeekdaysShort returns the locales short weekdays 207func (hr *hr) WeekdaysShort() []string { 208 return hr.daysShort 209} 210 211// WeekdayWide returns the locales wide weekday given the 'weekday' provided 212func (hr *hr) WeekdayWide(weekday time.Weekday) string { 213 return hr.daysWide[weekday] 214} 215 216// WeekdaysWide returns the locales wide weekdays 217func (hr *hr) WeekdaysWide() []string { 218 return hr.daysWide 219} 220 221// Decimal returns the decimal point of number 222func (hr *hr) Decimal() string { 223 return hr.decimal 224} 225 226// Group returns the group of number 227func (hr *hr) Group() string { 228 return hr.group 229} 230 231// Group returns the minus sign of number 232func (hr *hr) Minus() string { 233 return hr.minus 234} 235 236// FmtNumber returns 'num' with digits/precision of 'v' for 'hr' and handles both Whole and Real numbers based on 'v' 237func (hr *hr) FmtNumber(num float64, v uint64) string { 238 239 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 240 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3 241 count := 0 242 inWhole := v == 0 243 b := make([]byte, 0, l) 244 245 for i := len(s) - 1; i >= 0; i-- { 246 247 if s[i] == '.' { 248 b = append(b, hr.decimal[0]) 249 inWhole = true 250 continue 251 } 252 253 if inWhole { 254 if count == 3 { 255 b = append(b, hr.group[0]) 256 count = 1 257 } else { 258 count++ 259 } 260 } 261 262 b = append(b, s[i]) 263 } 264 265 if num < 0 { 266 b = append(b, hr.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 return string(b) 275} 276 277// FmtPercent returns 'num' with digits/precision of 'v' for 'hr' and handles both Whole and Real numbers based on 'v' 278// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 279func (hr *hr) FmtPercent(num float64, v uint64) string { 280 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 281 l := len(s) + 3 282 b := make([]byte, 0, l) 283 284 for i := len(s) - 1; i >= 0; i-- { 285 286 if s[i] == '.' { 287 b = append(b, hr.decimal[0]) 288 continue 289 } 290 291 b = append(b, s[i]) 292 } 293 294 if num < 0 { 295 b = append(b, hr.minus[0]) 296 } 297 298 // reverse 299 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 300 b[i], b[j] = b[j], b[i] 301 } 302 303 b = append(b, hr.percent...) 304 305 return string(b) 306} 307 308// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'hr' 309func (hr *hr) FmtCurrency(num float64, v uint64, currency currency.Type) string { 310 311 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 312 symbol := hr.currencies[currency] 313 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 314 count := 0 315 inWhole := v == 0 316 b := make([]byte, 0, l) 317 318 for i := len(s) - 1; i >= 0; i-- { 319 320 if s[i] == '.' { 321 b = append(b, hr.decimal[0]) 322 inWhole = true 323 continue 324 } 325 326 if inWhole { 327 if count == 3 { 328 b = append(b, hr.group[0]) 329 count = 1 330 } else { 331 count++ 332 } 333 } 334 335 b = append(b, s[i]) 336 } 337 338 if num < 0 { 339 b = append(b, hr.minus[0]) 340 } 341 342 // reverse 343 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 344 b[i], b[j] = b[j], b[i] 345 } 346 347 if int(v) < 2 { 348 349 if v == 0 { 350 b = append(b, hr.decimal...) 351 } 352 353 for i := 0; i < 2-int(v); i++ { 354 b = append(b, '0') 355 } 356 } 357 358 b = append(b, hr.currencyPositiveSuffix...) 359 360 b = append(b, symbol...) 361 362 return string(b) 363} 364 365// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'hr' 366// in accounting notation. 367func (hr *hr) FmtAccounting(num float64, v uint64, currency currency.Type) string { 368 369 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 370 symbol := hr.currencies[currency] 371 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 372 count := 0 373 inWhole := v == 0 374 b := make([]byte, 0, l) 375 376 for i := len(s) - 1; i >= 0; i-- { 377 378 if s[i] == '.' { 379 b = append(b, hr.decimal[0]) 380 inWhole = true 381 continue 382 } 383 384 if inWhole { 385 if count == 3 { 386 b = append(b, hr.group[0]) 387 count = 1 388 } else { 389 count++ 390 } 391 } 392 393 b = append(b, s[i]) 394 } 395 396 if num < 0 { 397 398 b = append(b, hr.minus[0]) 399 400 } 401 402 // reverse 403 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 404 b[i], b[j] = b[j], b[i] 405 } 406 407 if int(v) < 2 { 408 409 if v == 0 { 410 b = append(b, hr.decimal...) 411 } 412 413 for i := 0; i < 2-int(v); i++ { 414 b = append(b, '0') 415 } 416 } 417 418 if num < 0 { 419 b = append(b, hr.currencyNegativeSuffix...) 420 b = append(b, symbol...) 421 } else { 422 423 b = append(b, hr.currencyPositiveSuffix...) 424 b = append(b, symbol...) 425 } 426 427 return string(b) 428} 429 430// FmtDateShort returns the short date representation of 't' for 'hr' 431func (hr *hr) FmtDateShort(t time.Time) string { 432 433 b := make([]byte, 0, 32) 434 435 if t.Day() < 10 { 436 b = append(b, '0') 437 } 438 439 b = strconv.AppendInt(b, int64(t.Day()), 10) 440 b = append(b, []byte{0x2e, 0x20}...) 441 442 if t.Month() < 10 { 443 b = append(b, '0') 444 } 445 446 b = strconv.AppendInt(b, int64(t.Month()), 10) 447 448 b = append(b, []byte{0x2e, 0x20}...) 449 450 if t.Year() > 0 { 451 b = strconv.AppendInt(b, int64(t.Year()), 10) 452 } else { 453 b = strconv.AppendInt(b, int64(-t.Year()), 10) 454 } 455 456 b = append(b, []byte{0x2e}...) 457 458 return string(b) 459} 460 461// FmtDateMedium returns the medium date representation of 't' for 'hr' 462func (hr *hr) FmtDateMedium(t time.Time) string { 463 464 b := make([]byte, 0, 32) 465 466 b = strconv.AppendInt(b, int64(t.Day()), 10) 467 b = append(b, []byte{0x2e, 0x20}...) 468 b = append(b, hr.monthsAbbreviated[t.Month()]...) 469 b = append(b, []byte{0x20}...) 470 471 if t.Year() > 0 { 472 b = strconv.AppendInt(b, int64(t.Year()), 10) 473 } else { 474 b = strconv.AppendInt(b, int64(-t.Year()), 10) 475 } 476 477 b = append(b, []byte{0x2e}...) 478 479 return string(b) 480} 481 482// FmtDateLong returns the long date representation of 't' for 'hr' 483func (hr *hr) FmtDateLong(t time.Time) string { 484 485 b := make([]byte, 0, 32) 486 487 b = strconv.AppendInt(b, int64(t.Day()), 10) 488 b = append(b, []byte{0x2e, 0x20}...) 489 b = append(b, hr.monthsWide[t.Month()]...) 490 b = append(b, []byte{0x20}...) 491 492 if t.Year() > 0 { 493 b = strconv.AppendInt(b, int64(t.Year()), 10) 494 } else { 495 b = strconv.AppendInt(b, int64(-t.Year()), 10) 496 } 497 498 b = append(b, []byte{0x2e}...) 499 500 return string(b) 501} 502 503// FmtDateFull returns the full date representation of 't' for 'hr' 504func (hr *hr) FmtDateFull(t time.Time) string { 505 506 b := make([]byte, 0, 32) 507 508 b = append(b, hr.daysWide[t.Weekday()]...) 509 b = append(b, []byte{0x2c, 0x20}...) 510 b = strconv.AppendInt(b, int64(t.Day()), 10) 511 b = append(b, []byte{0x2e, 0x20}...) 512 b = append(b, hr.monthsWide[t.Month()]...) 513 b = append(b, []byte{0x20}...) 514 515 if t.Year() > 0 { 516 b = strconv.AppendInt(b, int64(t.Year()), 10) 517 } else { 518 b = strconv.AppendInt(b, int64(-t.Year()), 10) 519 } 520 521 b = append(b, []byte{0x2e}...) 522 523 return string(b) 524} 525 526// FmtTimeShort returns the short time representation of 't' for 'hr' 527func (hr *hr) FmtTimeShort(t time.Time) string { 528 529 b := make([]byte, 0, 32) 530 531 if t.Hour() < 10 { 532 b = append(b, '0') 533 } 534 535 b = strconv.AppendInt(b, int64(t.Hour()), 10) 536 b = append(b, hr.timeSeparator...) 537 538 if t.Minute() < 10 { 539 b = append(b, '0') 540 } 541 542 b = strconv.AppendInt(b, int64(t.Minute()), 10) 543 544 return string(b) 545} 546 547// FmtTimeMedium returns the medium time representation of 't' for 'hr' 548func (hr *hr) FmtTimeMedium(t time.Time) string { 549 550 b := make([]byte, 0, 32) 551 552 if t.Hour() < 10 { 553 b = append(b, '0') 554 } 555 556 b = strconv.AppendInt(b, int64(t.Hour()), 10) 557 b = append(b, hr.timeSeparator...) 558 559 if t.Minute() < 10 { 560 b = append(b, '0') 561 } 562 563 b = strconv.AppendInt(b, int64(t.Minute()), 10) 564 b = append(b, hr.timeSeparator...) 565 566 if t.Second() < 10 { 567 b = append(b, '0') 568 } 569 570 b = strconv.AppendInt(b, int64(t.Second()), 10) 571 572 return string(b) 573} 574 575// FmtTimeLong returns the long time representation of 't' for 'hr' 576func (hr *hr) FmtTimeLong(t time.Time) string { 577 578 b := make([]byte, 0, 32) 579 580 if t.Hour() < 10 { 581 b = append(b, '0') 582 } 583 584 b = strconv.AppendInt(b, int64(t.Hour()), 10) 585 b = append(b, hr.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, hr.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 tz, _ := t.Zone() 602 b = append(b, tz...) 603 604 return string(b) 605} 606 607// FmtTimeFull returns the full time representation of 't' for 'hr' 608func (hr *hr) FmtTimeFull(t time.Time) string { 609 610 b := make([]byte, 0, 32) 611 612 if t.Hour() < 10 { 613 b = append(b, '0') 614 } 615 616 b = strconv.AppendInt(b, int64(t.Hour()), 10) 617 b = append(b, hr.timeSeparator...) 618 619 if t.Minute() < 10 { 620 b = append(b, '0') 621 } 622 623 b = strconv.AppendInt(b, int64(t.Minute()), 10) 624 b = append(b, hr.timeSeparator...) 625 626 if t.Second() < 10 { 627 b = append(b, '0') 628 } 629 630 b = strconv.AppendInt(b, int64(t.Second()), 10) 631 b = append(b, []byte{0x20, 0x28}...) 632 633 tz, _ := t.Zone() 634 635 if btz, ok := hr.timezones[tz]; ok { 636 b = append(b, btz...) 637 } else { 638 b = append(b, tz...) 639 } 640 641 b = append(b, []byte{0x29}...) 642 643 return string(b) 644} 645