1package sl 2 3import ( 4 "math" 5 "strconv" 6 "time" 7 8 "github.com/gohugoio/locales" 9 "github.com/gohugoio/locales/currency" 10) 11 12type sl 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 currencyNegativePrefix string 28 currencyNegativeSuffix string 29 monthsAbbreviated []string 30 monthsNarrow []string 31 monthsWide []string 32 daysAbbreviated []string 33 daysNarrow []string 34 daysShort []string 35 daysWide []string 36 periodsAbbreviated []string 37 periodsNarrow []string 38 periodsShort []string 39 periodsWide []string 40 erasAbbreviated []string 41 erasNarrow []string 42 erasWide []string 43 timezones map[string]string 44} 45 46// New returns a new instance of translator for the 'sl' locale 47func New() locales.Translator { 48 return &sl{ 49 locale: "sl", 50 pluralsCardinal: []locales.PluralRule{2, 3, 4, 6}, 51 pluralsOrdinal: []locales.PluralRule{6}, 52 pluralsRange: []locales.PluralRule{3, 4, 6}, 53 decimal: ",", 54 group: ".", 55 minus: "−", 56 percent: "%", 57 perMille: "‰", 58 timeSeparator: ":", 59 inifinity: "∞", 60 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", "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", "GBP", "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", "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", "$", "USN", "USS", "UYI", "UYP", "UYU", "UYW", "UZS", "VEB", "VEF", "VES", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "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"}, 61 percentSuffix: " ", 62 currencyPositiveSuffix: " ", 63 currencyNegativePrefix: "(", 64 currencyNegativeSuffix: " )", 65 monthsAbbreviated: []string{"", "jan.", "feb.", "mar.", "apr.", "maj", "jun.", "jul.", "avg.", "sep.", "okt.", "nov.", "dec."}, 66 monthsNarrow: []string{"", "j", "f", "m", "a", "m", "j", "j", "a", "s", "o", "n", "d"}, 67 monthsWide: []string{"", "januar", "februar", "marec", "april", "maj", "junij", "julij", "avgust", "september", "oktober", "november", "december"}, 68 daysAbbreviated: []string{"ned.", "pon.", "tor.", "sre.", "čet.", "pet.", "sob."}, 69 daysNarrow: []string{"n", "p", "t", "s", "č", "p", "s"}, 70 daysShort: []string{"ned.", "pon.", "tor.", "sre.", "čet.", "pet.", "sob."}, 71 daysWide: []string{"nedelja", "ponedeljek", "torek", "sreda", "četrtek", "petek", "sobota"}, 72 periodsAbbreviated: []string{"dop.", "pop."}, 73 periodsNarrow: []string{"d", "p"}, 74 periodsWide: []string{"dop.", "pop."}, 75 erasAbbreviated: []string{"pr. Kr.", "po Kr."}, 76 erasNarrow: []string{"", ""}, 77 erasWide: []string{"pred Kristusom", "po Kristusu"}, 78 timezones: map[string]string{"ACDT": "Avstralski centralni poletni čas", "ACST": "Avstralski centralni standardni čas", "ACWDT": "Avstralski centralni zahodni poletni čas", "ACWST": "Avstralski centralni zahodni standardni čas", "ADT": "Atlantski poletni čas", "AEDT": "Avstralski vzhodni poletni čas", "AEST": "Avstralski vzhodni standardni čas", "AKDT": "Aljaški poletni čas", "AKST": "Aljaški standardni čas", "ARST": "Argentinski poletni čas", "ART": "Argentinski standardni čas", "AST": "Atlantski standardni čas", "AWDT": "Avstralski zahodni poletni čas", "AWST": "Avstralski zahodni standardni čas", "BOT": "Bolivijski čas", "BT": "Butanski čas", "CAT": "Centralnoafriški čas", "CDT": "Centralni poletni čas", "CHADT": "Čatamski poletni čas", "CHAST": "Čatamski standardni čas", "CLST": "Čilski poletni čas", "CLT": "Čilski standardni čas", "COST": "Kolumbijski poletni čas", "COT": "Kolumbijski standardni čas", "CST": "Centralni standardni čas", "ChST": "Čamorski standardni čas", "EAT": "Vzhodnoafriški čas", "ECT": "Ekvadorski čas", "EDT": "Vzhodni poletni čas", "EST": "Vzhodni standardni čas", "GFT": "Čas: Francoska Gvajana", "GMT": "Greenwiški srednji čas", "GST": "Zalivski standardni čas", "GYT": "Gvajanski čas", "HADT": "Havajski aleutski poletni čas", "HAST": "Havajski aleutski standardni čas", "HAT": "Novofundlandski poletni čas", "HECU": "Kubanski poletni čas", "HEEG": "Vzhodnogrenlandski poletni čas", "HENOMX": "Mehiški severozahodni poletni čas", "HEOG": "Zahodnogrenlandski poletni čas", "HEPM": "Poletni čas: Saint Pierre in Miquelon", "HEPMX": "Mehiški pacifiški poletni čas", "HKST": "Hongkonški poletni čas", "HKT": "Hongkonški standardni čas", "HNCU": "Kubanski standardni čas", "HNEG": "Vzhodnogrenlandski standardni čas", "HNNOMX": "Mehiški severozahodni standardni čas", "HNOG": "Zahodnogrenlandski standardni čas", "HNPM": "Standardni čas: Saint Pierre in Miquelon", "HNPMX": "Mehiški pacifiški standardni čas", "HNT": "Novofundlandski standardni čas", "IST": "Indijski standardni čas", "JDT": "Japonski poletni čas", "JST": "Japonski standardni čas", "LHDT": "Poletni čas otoka Lord Howe", "LHST": "Standardni čas otoka Lord Howe", "MDT": "Gorski poletni čas", "MESZ": "Srednjeevropski poletni čas", "MEZ": "Srednjeevropski standardni čas", "MST": "Gorski standardni čas", "MYT": "Malezijski čas", "NZDT": "Novozelandski poletni čas", "NZST": "Novozelandski standardni čas", "OESZ": "Vzhodnoevropski poletni čas", "OEZ": "Vzhodnoevropski standardni čas", "PDT": "Pacifiški poletni čas", "PST": "Pacifiški standardni čas", "SAST": "Južnoafriški čas", "SGT": "Singapurski standardni čas", "SRT": "Surinamski čas", "TMST": "Turkmenistanski poletni čas", "TMT": "Turkmenistanski standardni čas", "UYST": "Urugvajski poletni čas", "UYT": "Urugvajski standardni čas", "VET": "Venezuelski čas", "WARST": "Argentinski zahodni poletni čas", "WART": "Argentinski zahodni standardni čas", "WAST": "Zahodnoafriški poletni čas", "WAT": "Zahodnoafriški standardni čas", "WESZ": "Zahodnoevropski poletni čas", "WEZ": "Zahodnoevropski standardni čas", "WIB": "Indonezijski zahodni čas", "WIT": "Indonezijski vzhodni čas", "WITA": "Indonezijski osrednji čas", "∅∅∅": "Brasilski poletni čas"}, 79 } 80} 81 82// Locale returns the current translators string locale 83func (sl *sl) Locale() string { 84 return sl.locale 85} 86 87// PluralsCardinal returns the list of cardinal plural rules associated with 'sl' 88func (sl *sl) PluralsCardinal() []locales.PluralRule { 89 return sl.pluralsCardinal 90} 91 92// PluralsOrdinal returns the list of ordinal plural rules associated with 'sl' 93func (sl *sl) PluralsOrdinal() []locales.PluralRule { 94 return sl.pluralsOrdinal 95} 96 97// PluralsRange returns the list of range plural rules associated with 'sl' 98func (sl *sl) PluralsRange() []locales.PluralRule { 99 return sl.pluralsRange 100} 101 102// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'sl' 103func (sl *sl) CardinalPluralRule(num float64, v uint64) locales.PluralRule { 104 105 n := math.Abs(num) 106 i := int64(n) 107 iMod100 := i % 100 108 109 if v == 0 && iMod100 == 1 { 110 return locales.PluralRuleOne 111 } else if v == 0 && iMod100 == 2 { 112 return locales.PluralRuleTwo 113 } else if (v == 0 && iMod100 >= 3 && iMod100 <= 4) || (v != 0) { 114 return locales.PluralRuleFew 115 } 116 117 return locales.PluralRuleOther 118} 119 120// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'sl' 121func (sl *sl) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 122 return locales.PluralRuleOther 123} 124 125// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'sl' 126func (sl *sl) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 127 128 start := sl.CardinalPluralRule(num1, v1) 129 end := sl.CardinalPluralRule(num2, v2) 130 131 if start == locales.PluralRuleOne && end == locales.PluralRuleOne { 132 return locales.PluralRuleFew 133 } else if start == locales.PluralRuleOne && end == locales.PluralRuleTwo { 134 return locales.PluralRuleTwo 135 } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew { 136 return locales.PluralRuleFew 137 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther { 138 return locales.PluralRuleOther 139 } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOne { 140 return locales.PluralRuleFew 141 } else if start == locales.PluralRuleTwo && end == locales.PluralRuleTwo { 142 return locales.PluralRuleTwo 143 } else if start == locales.PluralRuleTwo && end == locales.PluralRuleFew { 144 return locales.PluralRuleFew 145 } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOther { 146 return locales.PluralRuleOther 147 } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne { 148 return locales.PluralRuleFew 149 } else if start == locales.PluralRuleFew && end == locales.PluralRuleTwo { 150 return locales.PluralRuleTwo 151 } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew { 152 return locales.PluralRuleFew 153 } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther { 154 return locales.PluralRuleOther 155 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne { 156 return locales.PluralRuleFew 157 } else if start == locales.PluralRuleOther && end == locales.PluralRuleTwo { 158 return locales.PluralRuleTwo 159 } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew { 160 return locales.PluralRuleFew 161 } 162 163 return locales.PluralRuleOther 164 165} 166 167// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 168func (sl *sl) MonthAbbreviated(month time.Month) string { 169 return sl.monthsAbbreviated[month] 170} 171 172// MonthsAbbreviated returns the locales abbreviated months 173func (sl *sl) MonthsAbbreviated() []string { 174 return sl.monthsAbbreviated[1:] 175} 176 177// MonthNarrow returns the locales narrow month given the 'month' provided 178func (sl *sl) MonthNarrow(month time.Month) string { 179 return sl.monthsNarrow[month] 180} 181 182// MonthsNarrow returns the locales narrow months 183func (sl *sl) MonthsNarrow() []string { 184 return sl.monthsNarrow[1:] 185} 186 187// MonthWide returns the locales wide month given the 'month' provided 188func (sl *sl) MonthWide(month time.Month) string { 189 return sl.monthsWide[month] 190} 191 192// MonthsWide returns the locales wide months 193func (sl *sl) MonthsWide() []string { 194 return sl.monthsWide[1:] 195} 196 197// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 198func (sl *sl) WeekdayAbbreviated(weekday time.Weekday) string { 199 return sl.daysAbbreviated[weekday] 200} 201 202// WeekdaysAbbreviated returns the locales abbreviated weekdays 203func (sl *sl) WeekdaysAbbreviated() []string { 204 return sl.daysAbbreviated 205} 206 207// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 208func (sl *sl) WeekdayNarrow(weekday time.Weekday) string { 209 return sl.daysNarrow[weekday] 210} 211 212// WeekdaysNarrow returns the locales narrow weekdays 213func (sl *sl) WeekdaysNarrow() []string { 214 return sl.daysNarrow 215} 216 217// WeekdayShort returns the locales short weekday given the 'weekday' provided 218func (sl *sl) WeekdayShort(weekday time.Weekday) string { 219 return sl.daysShort[weekday] 220} 221 222// WeekdaysShort returns the locales short weekdays 223func (sl *sl) WeekdaysShort() []string { 224 return sl.daysShort 225} 226 227// WeekdayWide returns the locales wide weekday given the 'weekday' provided 228func (sl *sl) WeekdayWide(weekday time.Weekday) string { 229 return sl.daysWide[weekday] 230} 231 232// WeekdaysWide returns the locales wide weekdays 233func (sl *sl) WeekdaysWide() []string { 234 return sl.daysWide 235} 236 237// Decimal returns the decimal point of number 238func (sl *sl) Decimal() string { 239 return sl.decimal 240} 241 242// Group returns the group of number 243func (sl *sl) Group() string { 244 return sl.group 245} 246 247// Group returns the minus sign of number 248func (sl *sl) Minus() string { 249 return sl.minus 250} 251 252// FmtNumber returns 'num' with digits/precision of 'v' for 'sl' and handles both Whole and Real numbers based on 'v' 253func (sl *sl) FmtNumber(num float64, v uint64) string { 254 255 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 256 l := len(s) + 4 + 1*len(s[:len(s)-int(v)-1])/3 257 count := 0 258 inWhole := v == 0 259 b := make([]byte, 0, l) 260 261 for i := len(s) - 1; i >= 0; i-- { 262 263 if s[i] == '.' { 264 b = append(b, sl.decimal[0]) 265 inWhole = true 266 continue 267 } 268 269 if inWhole { 270 if count == 3 { 271 b = append(b, sl.group[0]) 272 count = 1 273 } else { 274 count++ 275 } 276 } 277 278 b = append(b, s[i]) 279 } 280 281 if num < 0 { 282 for j := len(sl.minus) - 1; j >= 0; j-- { 283 b = append(b, sl.minus[j]) 284 } 285 } 286 287 // reverse 288 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 289 b[i], b[j] = b[j], b[i] 290 } 291 292 return string(b) 293} 294 295// FmtPercent returns 'num' with digits/precision of 'v' for 'sl' and handles both Whole and Real numbers based on 'v' 296// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 297func (sl *sl) FmtPercent(num float64, v uint64) string { 298 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 299 l := len(s) + 7 300 b := make([]byte, 0, l) 301 302 for i := len(s) - 1; i >= 0; i-- { 303 304 if s[i] == '.' { 305 b = append(b, sl.decimal[0]) 306 continue 307 } 308 309 b = append(b, s[i]) 310 } 311 312 if num < 0 { 313 for j := len(sl.minus) - 1; j >= 0; j-- { 314 b = append(b, sl.minus[j]) 315 } 316 } 317 318 // reverse 319 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 320 b[i], b[j] = b[j], b[i] 321 } 322 323 b = append(b, sl.percentSuffix...) 324 325 b = append(b, sl.percent...) 326 327 return string(b) 328} 329 330// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'sl' 331func (sl *sl) FmtCurrency(num float64, v uint64, currency currency.Type) string { 332 333 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 334 symbol := sl.currencies[currency] 335 l := len(s) + len(symbol) + 6 + 1*len(s[:len(s)-int(v)-1])/3 336 count := 0 337 inWhole := v == 0 338 b := make([]byte, 0, l) 339 340 for i := len(s) - 1; i >= 0; i-- { 341 342 if s[i] == '.' { 343 b = append(b, sl.decimal[0]) 344 inWhole = true 345 continue 346 } 347 348 if inWhole { 349 if count == 3 { 350 b = append(b, sl.group[0]) 351 count = 1 352 } else { 353 count++ 354 } 355 } 356 357 b = append(b, s[i]) 358 } 359 360 if num < 0 { 361 for j := len(sl.minus) - 1; j >= 0; j-- { 362 b = append(b, sl.minus[j]) 363 } 364 } 365 366 // reverse 367 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 368 b[i], b[j] = b[j], b[i] 369 } 370 371 if int(v) < 2 { 372 373 if v == 0 { 374 b = append(b, sl.decimal...) 375 } 376 377 for i := 0; i < 2-int(v); i++ { 378 b = append(b, '0') 379 } 380 } 381 382 b = append(b, sl.currencyPositiveSuffix...) 383 384 b = append(b, symbol...) 385 386 return string(b) 387} 388 389// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'sl' 390// in accounting notation. 391func (sl *sl) FmtAccounting(num float64, v uint64, currency currency.Type) string { 392 393 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 394 symbol := sl.currencies[currency] 395 l := len(s) + len(symbol) + 8 + 1*len(s[:len(s)-int(v)-1])/3 396 count := 0 397 inWhole := v == 0 398 b := make([]byte, 0, l) 399 400 for i := len(s) - 1; i >= 0; i-- { 401 402 if s[i] == '.' { 403 b = append(b, sl.decimal[0]) 404 inWhole = true 405 continue 406 } 407 408 if inWhole { 409 if count == 3 { 410 b = append(b, sl.group[0]) 411 count = 1 412 } else { 413 count++ 414 } 415 } 416 417 b = append(b, s[i]) 418 } 419 420 if num < 0 { 421 422 b = append(b, sl.currencyNegativePrefix[0]) 423 424 } 425 426 // reverse 427 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 428 b[i], b[j] = b[j], b[i] 429 } 430 431 if int(v) < 2 { 432 433 if v == 0 { 434 b = append(b, sl.decimal...) 435 } 436 437 for i := 0; i < 2-int(v); i++ { 438 b = append(b, '0') 439 } 440 } 441 442 if num < 0 { 443 b = append(b, sl.currencyNegativeSuffix...) 444 b = append(b, symbol...) 445 } else { 446 447 b = append(b, sl.currencyPositiveSuffix...) 448 b = append(b, symbol...) 449 } 450 451 return string(b) 452} 453 454// FmtDateShort returns the short date representation of 't' for 'sl' 455func (sl *sl) FmtDateShort(t time.Time) string { 456 457 b := make([]byte, 0, 32) 458 459 b = strconv.AppendInt(b, int64(t.Day()), 10) 460 b = append(b, []byte{0x2e, 0x20}...) 461 462 if t.Month() < 10 { 463 b = append(b, '0') 464 } 465 466 b = strconv.AppendInt(b, int64(t.Month()), 10) 467 468 b = append(b, []byte{0x2e, 0x20}...) 469 470 if t.Year() > 9 { 471 b = append(b, strconv.Itoa(t.Year())[2:]...) 472 } else { 473 b = append(b, strconv.Itoa(t.Year())[1:]...) 474 } 475 476 return string(b) 477} 478 479// FmtDateMedium returns the medium date representation of 't' for 'sl' 480func (sl *sl) FmtDateMedium(t time.Time) string { 481 482 b := make([]byte, 0, 32) 483 484 b = strconv.AppendInt(b, int64(t.Day()), 10) 485 b = append(b, []byte{0x2e, 0x20}...) 486 b = append(b, sl.monthsAbbreviated[t.Month()]...) 487 b = append(b, []byte{0x20}...) 488 489 if t.Year() > 0 { 490 b = strconv.AppendInt(b, int64(t.Year()), 10) 491 } else { 492 b = strconv.AppendInt(b, int64(-t.Year()), 10) 493 } 494 495 return string(b) 496} 497 498// FmtDateLong returns the long date representation of 't' for 'sl' 499func (sl *sl) FmtDateLong(t time.Time) string { 500 501 b := make([]byte, 0, 32) 502 503 if t.Day() < 10 { 504 b = append(b, '0') 505 } 506 507 b = strconv.AppendInt(b, int64(t.Day()), 10) 508 b = append(b, []byte{0x2e, 0x20}...) 509 b = append(b, sl.monthsWide[t.Month()]...) 510 b = append(b, []byte{0x20}...) 511 512 if t.Year() > 0 { 513 b = strconv.AppendInt(b, int64(t.Year()), 10) 514 } else { 515 b = strconv.AppendInt(b, int64(-t.Year()), 10) 516 } 517 518 return string(b) 519} 520 521// FmtDateFull returns the full date representation of 't' for 'sl' 522func (sl *sl) FmtDateFull(t time.Time) string { 523 524 b := make([]byte, 0, 32) 525 526 b = append(b, sl.daysWide[t.Weekday()]...) 527 b = append(b, []byte{0x2c, 0x20}...) 528 529 if t.Day() < 10 { 530 b = append(b, '0') 531 } 532 533 b = strconv.AppendInt(b, int64(t.Day()), 10) 534 b = append(b, []byte{0x2e, 0x20}...) 535 b = append(b, sl.monthsWide[t.Month()]...) 536 b = append(b, []byte{0x20}...) 537 538 if t.Year() > 0 { 539 b = strconv.AppendInt(b, int64(t.Year()), 10) 540 } else { 541 b = strconv.AppendInt(b, int64(-t.Year()), 10) 542 } 543 544 return string(b) 545} 546 547// FmtTimeShort returns the short time representation of 't' for 'sl' 548func (sl *sl) FmtTimeShort(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, sl.timeSeparator...) 558 559 if t.Minute() < 10 { 560 b = append(b, '0') 561 } 562 563 b = strconv.AppendInt(b, int64(t.Minute()), 10) 564 565 return string(b) 566} 567 568// FmtTimeMedium returns the medium time representation of 't' for 'sl' 569func (sl *sl) FmtTimeMedium(t time.Time) string { 570 571 b := make([]byte, 0, 32) 572 573 if t.Hour() < 10 { 574 b = append(b, '0') 575 } 576 577 b = strconv.AppendInt(b, int64(t.Hour()), 10) 578 b = append(b, sl.timeSeparator...) 579 580 if t.Minute() < 10 { 581 b = append(b, '0') 582 } 583 584 b = strconv.AppendInt(b, int64(t.Minute()), 10) 585 b = append(b, sl.timeSeparator...) 586 587 if t.Second() < 10 { 588 b = append(b, '0') 589 } 590 591 b = strconv.AppendInt(b, int64(t.Second()), 10) 592 593 return string(b) 594} 595 596// FmtTimeLong returns the long time representation of 't' for 'sl' 597func (sl *sl) FmtTimeLong(t time.Time) string { 598 599 b := make([]byte, 0, 32) 600 601 if t.Hour() < 10 { 602 b = append(b, '0') 603 } 604 605 b = strconv.AppendInt(b, int64(t.Hour()), 10) 606 b = append(b, sl.timeSeparator...) 607 608 if t.Minute() < 10 { 609 b = append(b, '0') 610 } 611 612 b = strconv.AppendInt(b, int64(t.Minute()), 10) 613 b = append(b, sl.timeSeparator...) 614 615 if t.Second() < 10 { 616 b = append(b, '0') 617 } 618 619 b = strconv.AppendInt(b, int64(t.Second()), 10) 620 b = append(b, []byte{0x20}...) 621 622 tz, _ := t.Zone() 623 b = append(b, tz...) 624 625 return string(b) 626} 627 628// FmtTimeFull returns the full time representation of 't' for 'sl' 629func (sl *sl) FmtTimeFull(t time.Time) string { 630 631 b := make([]byte, 0, 32) 632 633 if t.Hour() < 10 { 634 b = append(b, '0') 635 } 636 637 b = strconv.AppendInt(b, int64(t.Hour()), 10) 638 b = append(b, sl.timeSeparator...) 639 640 if t.Minute() < 10 { 641 b = append(b, '0') 642 } 643 644 b = strconv.AppendInt(b, int64(t.Minute()), 10) 645 b = append(b, sl.timeSeparator...) 646 647 if t.Second() < 10 { 648 b = append(b, '0') 649 } 650 651 b = strconv.AppendInt(b, int64(t.Second()), 10) 652 b = append(b, []byte{0x20}...) 653 654 tz, _ := t.Zone() 655 656 if btz, ok := sl.timezones[tz]; ok { 657 b = append(b, btz...) 658 } else { 659 b = append(b, tz...) 660 } 661 662 return string(b) 663} 664