1package as 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 as 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 currencyPositivePrefix string 26 currencyNegativePrefix 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 'as' locale 45func New() locales.Translator { 46 return &as{ 47 locale: "as", 48 pluralsCardinal: []locales.PluralRule{2, 6}, 49 pluralsOrdinal: []locales.PluralRule{2, 3, 4, 5, 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", "JP¥", "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", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "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"}, 59 currencyPositivePrefix: " ", 60 currencyNegativePrefix: " ", 61 monthsAbbreviated: []string{"", "জানু", "ফেব্ৰু", "মাৰ্চ", "এপ্ৰিল", "মে’", "জুন", "জুলাই", "আগ", "ছেপ্তে", "অক্টো", "নৱে", "ডিচে"}, 62 monthsNarrow: []string{"", "জ", "ফ", "ম", "এ", "ম", "জ", "জ", "আ", "ছ", "অ", "ন", "ড"}, 63 monthsWide: []string{"", "জানুৱাৰী", "ফেব্ৰুৱাৰী", "মাৰ্চ", "এপ্ৰিল", "মে’", "জুন", "জুলাই", "আগষ্ট", "ছেপ্তেম্বৰ", "অক্টোবৰ", "নৱেম্বৰ", "ডিচেম্বৰ"}, 64 daysAbbreviated: []string{"দেও", "সোম", "মঙ্গল", "বুধ", "বৃহ", "শুক্ৰ", "শনি"}, 65 daysNarrow: []string{"দ", "স", "ম", "ব", "ব", "শ", "শ"}, 66 daysShort: []string{"দেও", "সোম", "মঙ্গল", "বুধ", "বৃহ", "শুক্ৰ", "শনি"}, 67 daysWide: []string{"দেওবাৰ", "সোমবাৰ", "মঙ্গলবাৰ", "বুধবাৰ", "বৃহস্পতিবাৰ", "শুক্ৰবাৰ", "শনিবাৰ"}, 68 periodsAbbreviated: []string{"পূৰ্বাহ্ণ", "অপৰাহ্ণ"}, 69 periodsNarrow: []string{"পূৰ্বাহ্ণ", "অপৰাহ্ণ"}, 70 periodsWide: []string{"পূৰ্বাহ্ণ", "অপৰাহ্ণ"}, 71 erasAbbreviated: []string{"", ""}, 72 erasNarrow: []string{"", ""}, 73 erasWide: []string{"খ্ৰীষ্টপূৰ্ব", "খ্ৰীষ্টাব্দ"}, 74 timezones: map[string]string{"AEDT": "অস্ট্রেলিয়ান পূর্ব দিবালোক সময়", "BT": "ভুটান টাইম", "WARST": "ওয়েস্টার্ন আর্জেন্টিনা গ্রীষ্মকালীন সময়", "IST": "ভাৰতীয় সময়", "WITA": "মধ্য ইন্দোনেশিয়া সময়", "WEZ": "পশ্চিম ইউরোপীয় মান সময়", "JDT": "জাপান দিনের হালকা সময়", "HEEG": "HEEG", "HENOMX": "HENOMX", "OEZ": "পূর্ব ইউরোপীয় মান সময়", "COT": "কলম্বিয়া মান সময়", "CST": "CST", "SAST": "দক্ষিণ আফ্রিকা মান সময়", "SGT": "সিঙ্গাপুর স্ট্যান্ডার্ড টাইম", "ACWST": "অস্ট্রেলিয়ান সেন্ট্রাল ওয়েস্টার্ন স্ট্যান্ডার্ড টাইম", "LHDT": "লর্ড হ্যালো দিবালোক সময়", "TMST": "তুর্কমেনিস্তান গ্রীষ্ম সময়", "ART": "আৰ্জেণ্টিনা মান সময়", "PDT": "PDT", "AWST": "অস্ট্রেলিয়ান ওয়েস্টার্ন স্ট্যান্ডার্ড টাইম", "ADT": "ADT", "OESZ": "পূর্ব ইউরোপীয় গ্রীষ্মকালীন সময়", "BOT": "বলিভিয়া সময়", "ACST": "অস্ট্রেলিয়ান কেন্দ্রীয় স্ট্যান্ডার্ড টাইম", "ACDT": "অস্ট্রেলিয়ান কেন্দ্রীয় দিবালোক সময়", "CHAST": "চ্যাথাম স্ট্যান্ডার্ড টাইম", "∅∅∅": "ব্ৰাছিলিয়া গ্ৰীষ্ম সময়", "WIB": "ওয়েস্টার্ন ইন্দোনেশিয়া সময়", "AWDT": "অস্ট্রেলিয়ান ওয়েস্টার্ন ডেলাইট টাইম", "HNT": "HNT", "WIT": "ইস্টার্ন ইন্দোনেশিয়া সময়", "UYT": "উৰুগুৱে মান সময়", "HNCU": "HNCU", "HECU": "HECU", "PST": "PST", "HNNOMX": "HNNOMX", "ARST": "আৰ্জেণ্টিনা গ্ৰীষ্ম সময়", "WESZ": "পশ্চিম ইউরোপীয় গ্রীষ্মকালীন সময়", "NZST": "নিউজিল্যান্ড স্ট্যান্ডার্ড টাইম", "JST": "জাপান স্ট্যান্ডার্ড টাইম", "HKST": "হংকং গ্রীষ্মকালীন সময়", "LHST": "লর্ড হাভী স্ট্যান্ডার্ড টাইম", "CLT": "চিলি স্ট্যান্ডার্ড টাইম", "GYT": "গায়ানা টাইম", "ChST": "চামেরো স্ট্যান্ডার্ড টাইম", "HNPMX": "HNPMX", "WAST": "পশ্চিম আফ্রিকার গ্রীষ্মকালীন সময়", "VET": "ভেনিজুয়েলা সময়", "CAT": "মধ্য আফ্রিকা সময়", "CLST": "চিলি গ্রীষ্মকালীন সময়", "AKST": "AKST", "AKDT": "AKDT", "MEZ": "কেন্দ্রীয় ইউরোপীয় স্ট্যান্ডার্ড টাইম", "AEST": "অস্ট্রেলিয়ান ইস্টার্ন স্ট্যান্ডার্ড টাইম", "MYT": "মালয়েশিয়া সময়", "COST": "কলম্বিয়া গ্ৰীষ্ম সময়", "TMT": "তুর্কমেনিস্তান মান সময়", "CHADT": "চ্যাথাম ডেইলাইট টাইম", "AST": "AST", "EST": "EST", "GMT": "মক্কার সময়", "ECT": "ইকুৱেডৰ সময়", "EDT": "EDT", "HNPM": "HNPM", "GFT": "ফরাসি গায়ানা সময়", "HEPM": "HEPM", "CDT": "CDT", "MST": "MST", "MDT": "MDT", "HADT": "HADT", "HNEG": "HNEG", "HKT": "হংকং স্ট্যান্ডার্ড টাইম", "HAST": "HAST", "ACWDT": "অস্ট্রেলিয়ান সেন্ট্রাল ওয়েস্টার্ন ডেলাইট টাইম", "HNOG": "HNOG", "HEOG": "HEOG", "MESZ": "মধ্য ইউরোপীয় গ্রীষ্মকালীন সময়", "WART": "ওয়েস্টার্ন আর্জেন্টিনা মান সময়", "HEPMX": "HEPMX", "WAT": "পশ্চিম আফ্রিকার মান সময়", "NZDT": "নিউজিল্যান্ড ডেলাইট টাইম", "UYST": "উৰুগুৱে গ্ৰীষ্ম সময়", "HAT": "HAT", "SRT": "সুরিনাম টাইম", "EAT": "পূর্ব আফ্রিকা সময়"}, 75 } 76} 77 78// Locale returns the current translators string locale 79func (as *as) Locale() string { 80 return as.locale 81} 82 83// PluralsCardinal returns the list of cardinal plural rules associated with 'as' 84func (as *as) PluralsCardinal() []locales.PluralRule { 85 return as.pluralsCardinal 86} 87 88// PluralsOrdinal returns the list of ordinal plural rules associated with 'as' 89func (as *as) PluralsOrdinal() []locales.PluralRule { 90 return as.pluralsOrdinal 91} 92 93// PluralsRange returns the list of range plural rules associated with 'as' 94func (as *as) PluralsRange() []locales.PluralRule { 95 return as.pluralsRange 96} 97 98// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'as' 99func (as *as) CardinalPluralRule(num float64, v uint64) locales.PluralRule { 100 101 n := math.Abs(num) 102 i := int64(n) 103 104 if (i == 0) || (n == 1) { 105 return locales.PluralRuleOne 106 } 107 108 return locales.PluralRuleOther 109} 110 111// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'as' 112func (as *as) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 113 114 n := math.Abs(num) 115 116 if n == 1 || n == 5 || n == 7 || n == 8 || n == 9 || n == 10 { 117 return locales.PluralRuleOne 118 } else if n == 2 || n == 3 { 119 return locales.PluralRuleTwo 120 } else if n == 4 { 121 return locales.PluralRuleFew 122 } else if n == 6 { 123 return locales.PluralRuleMany 124 } 125 126 return locales.PluralRuleOther 127} 128 129// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'as' 130func (as *as) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 131 132 start := as.CardinalPluralRule(num1, v1) 133 end := as.CardinalPluralRule(num2, v2) 134 135 if start == locales.PluralRuleOne && end == locales.PluralRuleOne { 136 return locales.PluralRuleOne 137 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther { 138 return locales.PluralRuleOther 139 } 140 141 return locales.PluralRuleOther 142 143} 144 145// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 146func (as *as) MonthAbbreviated(month time.Month) string { 147 return as.monthsAbbreviated[month] 148} 149 150// MonthsAbbreviated returns the locales abbreviated months 151func (as *as) MonthsAbbreviated() []string { 152 return as.monthsAbbreviated[1:] 153} 154 155// MonthNarrow returns the locales narrow month given the 'month' provided 156func (as *as) MonthNarrow(month time.Month) string { 157 return as.monthsNarrow[month] 158} 159 160// MonthsNarrow returns the locales narrow months 161func (as *as) MonthsNarrow() []string { 162 return as.monthsNarrow[1:] 163} 164 165// MonthWide returns the locales wide month given the 'month' provided 166func (as *as) MonthWide(month time.Month) string { 167 return as.monthsWide[month] 168} 169 170// MonthsWide returns the locales wide months 171func (as *as) MonthsWide() []string { 172 return as.monthsWide[1:] 173} 174 175// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 176func (as *as) WeekdayAbbreviated(weekday time.Weekday) string { 177 return as.daysAbbreviated[weekday] 178} 179 180// WeekdaysAbbreviated returns the locales abbreviated weekdays 181func (as *as) WeekdaysAbbreviated() []string { 182 return as.daysAbbreviated 183} 184 185// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 186func (as *as) WeekdayNarrow(weekday time.Weekday) string { 187 return as.daysNarrow[weekday] 188} 189 190// WeekdaysNarrow returns the locales narrow weekdays 191func (as *as) WeekdaysNarrow() []string { 192 return as.daysNarrow 193} 194 195// WeekdayShort returns the locales short weekday given the 'weekday' provided 196func (as *as) WeekdayShort(weekday time.Weekday) string { 197 return as.daysShort[weekday] 198} 199 200// WeekdaysShort returns the locales short weekdays 201func (as *as) WeekdaysShort() []string { 202 return as.daysShort 203} 204 205// WeekdayWide returns the locales wide weekday given the 'weekday' provided 206func (as *as) WeekdayWide(weekday time.Weekday) string { 207 return as.daysWide[weekday] 208} 209 210// WeekdaysWide returns the locales wide weekdays 211func (as *as) WeekdaysWide() []string { 212 return as.daysWide 213} 214 215// Decimal returns the decimal point of number 216func (as *as) Decimal() string { 217 return as.decimal 218} 219 220// Group returns the group of number 221func (as *as) Group() string { 222 return as.group 223} 224 225// Group returns the minus sign of number 226func (as *as) Minus() string { 227 return as.minus 228} 229 230// FmtNumber returns 'num' with digits/precision of 'v' for 'as' and handles both Whole and Real numbers based on 'v' 231func (as *as) FmtNumber(num float64, v uint64) string { 232 233 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 234 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3 235 count := 0 236 inWhole := v == 0 237 inSecondary := false 238 groupThreshold := 3 239 240 b := make([]byte, 0, l) 241 242 for i := len(s) - 1; i >= 0; i-- { 243 244 if s[i] == '.' { 245 b = append(b, as.decimal[0]) 246 inWhole = true 247 continue 248 } 249 250 if inWhole { 251 252 if count == groupThreshold { 253 b = append(b, as.group[0]) 254 count = 1 255 256 if !inSecondary { 257 inSecondary = true 258 groupThreshold = 2 259 } 260 } else { 261 count++ 262 } 263 } 264 265 b = append(b, s[i]) 266 } 267 268 if num < 0 { 269 b = append(b, as.minus[0]) 270 } 271 272 // reverse 273 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 274 b[i], b[j] = b[j], b[i] 275 } 276 277 return string(b) 278} 279 280// FmtPercent returns 'num' with digits/precision of 'v' for 'as' and handles both Whole and Real numbers based on 'v' 281// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 282func (as *as) FmtPercent(num float64, v uint64) string { 283 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 284 l := len(s) + 3 285 b := make([]byte, 0, l) 286 287 for i := len(s) - 1; i >= 0; i-- { 288 289 if s[i] == '.' { 290 b = append(b, as.decimal[0]) 291 continue 292 } 293 294 b = append(b, s[i]) 295 } 296 297 if num < 0 { 298 b = append(b, as.minus[0]) 299 } 300 301 // reverse 302 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 303 b[i], b[j] = b[j], b[i] 304 } 305 306 b = append(b, as.percent...) 307 308 return string(b) 309} 310 311// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'as' 312func (as *as) FmtCurrency(num float64, v uint64, currency currency.Type) string { 313 314 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 315 symbol := as.currencies[currency] 316 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 317 count := 0 318 inWhole := v == 0 319 inSecondary := false 320 groupThreshold := 3 321 322 b := make([]byte, 0, l) 323 324 for i := len(s) - 1; i >= 0; i-- { 325 326 if s[i] == '.' { 327 b = append(b, as.decimal[0]) 328 inWhole = true 329 continue 330 } 331 332 if inWhole { 333 334 if count == groupThreshold { 335 b = append(b, as.group[0]) 336 count = 1 337 338 if !inSecondary { 339 inSecondary = true 340 groupThreshold = 2 341 } 342 } else { 343 count++ 344 } 345 } 346 347 b = append(b, s[i]) 348 } 349 350 for j := len(symbol) - 1; j >= 0; j-- { 351 b = append(b, symbol[j]) 352 } 353 354 for j := len(as.currencyPositivePrefix) - 1; j >= 0; j-- { 355 b = append(b, as.currencyPositivePrefix[j]) 356 } 357 358 if num < 0 { 359 b = append(b, as.minus[0]) 360 } 361 362 // reverse 363 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 364 b[i], b[j] = b[j], b[i] 365 } 366 367 if int(v) < 2 { 368 369 if v == 0 { 370 b = append(b, as.decimal...) 371 } 372 373 for i := 0; i < 2-int(v); i++ { 374 b = append(b, '0') 375 } 376 } 377 378 return string(b) 379} 380 381// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'as' 382// in accounting notation. 383func (as *as) FmtAccounting(num float64, v uint64, currency currency.Type) string { 384 385 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 386 symbol := as.currencies[currency] 387 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3 388 count := 0 389 inWhole := v == 0 390 inSecondary := false 391 groupThreshold := 3 392 393 b := make([]byte, 0, l) 394 395 for i := len(s) - 1; i >= 0; i-- { 396 397 if s[i] == '.' { 398 b = append(b, as.decimal[0]) 399 inWhole = true 400 continue 401 } 402 403 if inWhole { 404 405 if count == groupThreshold { 406 b = append(b, as.group[0]) 407 count = 1 408 409 if !inSecondary { 410 inSecondary = true 411 groupThreshold = 2 412 } 413 } else { 414 count++ 415 } 416 } 417 418 b = append(b, s[i]) 419 } 420 421 if num < 0 { 422 423 for j := len(symbol) - 1; j >= 0; j-- { 424 b = append(b, symbol[j]) 425 } 426 427 for j := len(as.currencyNegativePrefix) - 1; j >= 0; j-- { 428 b = append(b, as.currencyNegativePrefix[j]) 429 } 430 431 b = append(b, as.minus[0]) 432 433 } else { 434 435 for j := len(symbol) - 1; j >= 0; j-- { 436 b = append(b, symbol[j]) 437 } 438 439 for j := len(as.currencyPositivePrefix) - 1; j >= 0; j-- { 440 b = append(b, as.currencyPositivePrefix[j]) 441 } 442 443 } 444 445 // reverse 446 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 447 b[i], b[j] = b[j], b[i] 448 } 449 450 if int(v) < 2 { 451 452 if v == 0 { 453 b = append(b, as.decimal...) 454 } 455 456 for i := 0; i < 2-int(v); i++ { 457 b = append(b, '0') 458 } 459 } 460 461 return string(b) 462} 463 464// FmtDateShort returns the short date representation of 't' for 'as' 465func (as *as) FmtDateShort(t time.Time) string { 466 467 b := make([]byte, 0, 32) 468 469 b = strconv.AppendInt(b, int64(t.Day()), 10) 470 b = append(b, []byte{0x2d}...) 471 b = strconv.AppendInt(b, int64(t.Month()), 10) 472 b = append(b, []byte{0x2d}...) 473 474 if t.Year() > 0 { 475 b = strconv.AppendInt(b, int64(t.Year()), 10) 476 } else { 477 b = strconv.AppendInt(b, int64(-t.Year()), 10) 478 } 479 480 return string(b) 481} 482 483// FmtDateMedium returns the medium date representation of 't' for 'as' 484func (as *as) FmtDateMedium(t time.Time) string { 485 486 b := make([]byte, 0, 32) 487 488 if t.Day() < 10 { 489 b = append(b, '0') 490 } 491 492 b = strconv.AppendInt(b, int64(t.Day()), 10) 493 b = append(b, []byte{0x2d}...) 494 495 if t.Month() < 10 { 496 b = append(b, '0') 497 } 498 499 b = strconv.AppendInt(b, int64(t.Month()), 10) 500 501 b = append(b, []byte{0x2d}...) 502 503 if t.Year() > 0 { 504 b = strconv.AppendInt(b, int64(t.Year()), 10) 505 } else { 506 b = strconv.AppendInt(b, int64(-t.Year()), 10) 507 } 508 509 return string(b) 510} 511 512// FmtDateLong returns the long date representation of 't' for 'as' 513func (as *as) FmtDateLong(t time.Time) string { 514 515 b := make([]byte, 0, 32) 516 517 b = strconv.AppendInt(b, int64(t.Day()), 10) 518 b = append(b, []byte{0x20}...) 519 b = append(b, as.monthsWide[t.Month()]...) 520 b = append(b, []byte{0x2c, 0x20}...) 521 522 if t.Year() > 0 { 523 b = strconv.AppendInt(b, int64(t.Year()), 10) 524 } else { 525 b = strconv.AppendInt(b, int64(-t.Year()), 10) 526 } 527 528 return string(b) 529} 530 531// FmtDateFull returns the full date representation of 't' for 'as' 532func (as *as) FmtDateFull(t time.Time) string { 533 534 b := make([]byte, 0, 32) 535 536 b = append(b, as.daysWide[t.Weekday()]...) 537 b = append(b, []byte{0x2c, 0x20}...) 538 b = strconv.AppendInt(b, int64(t.Day()), 10) 539 b = append(b, []byte{0x20}...) 540 b = append(b, as.monthsWide[t.Month()]...) 541 b = append(b, []byte{0x2c, 0x20}...) 542 543 if t.Year() > 0 { 544 b = strconv.AppendInt(b, int64(t.Year()), 10) 545 } else { 546 b = strconv.AppendInt(b, int64(-t.Year()), 10) 547 } 548 549 return string(b) 550} 551 552// FmtTimeShort returns the short time representation of 't' for 'as' 553func (as *as) FmtTimeShort(t time.Time) string { 554 555 b := make([]byte, 0, 32) 556 557 h := t.Hour() 558 559 if h > 12 { 560 h -= 12 561 } 562 563 b = strconv.AppendInt(b, int64(h), 10) 564 b = append(b, []byte{0x2e}...) 565 566 if t.Minute() < 10 { 567 b = append(b, '0') 568 } 569 570 b = strconv.AppendInt(b, int64(t.Minute()), 10) 571 b = append(b, []byte{0x2e, 0x20}...) 572 573 if t.Hour() < 12 { 574 b = append(b, as.periodsAbbreviated[0]...) 575 } else { 576 b = append(b, as.periodsAbbreviated[1]...) 577 } 578 579 return string(b) 580} 581 582// FmtTimeMedium returns the medium time representation of 't' for 'as' 583func (as *as) FmtTimeMedium(t time.Time) string { 584 585 b := make([]byte, 0, 32) 586 587 h := t.Hour() 588 589 if h > 12 { 590 h -= 12 591 } 592 593 b = strconv.AppendInt(b, int64(h), 10) 594 b = append(b, []byte{0x2e}...) 595 596 if t.Minute() < 10 { 597 b = append(b, '0') 598 } 599 600 b = strconv.AppendInt(b, int64(t.Minute()), 10) 601 b = append(b, []byte{0x2e}...) 602 603 if t.Second() < 10 { 604 b = append(b, '0') 605 } 606 607 b = strconv.AppendInt(b, int64(t.Second()), 10) 608 b = append(b, []byte{0x20}...) 609 610 if t.Hour() < 12 { 611 b = append(b, as.periodsAbbreviated[0]...) 612 } else { 613 b = append(b, as.periodsAbbreviated[1]...) 614 } 615 616 return string(b) 617} 618 619// FmtTimeLong returns the long time representation of 't' for 'as' 620func (as *as) FmtTimeLong(t time.Time) string { 621 622 b := make([]byte, 0, 32) 623 624 h := t.Hour() 625 626 if h > 12 { 627 h -= 12 628 } 629 630 b = strconv.AppendInt(b, int64(h), 10) 631 b = append(b, []byte{0x2e}...) 632 633 if t.Minute() < 10 { 634 b = append(b, '0') 635 } 636 637 b = strconv.AppendInt(b, int64(t.Minute()), 10) 638 b = append(b, []byte{0x2e}...) 639 640 if t.Second() < 10 { 641 b = append(b, '0') 642 } 643 644 b = strconv.AppendInt(b, int64(t.Second()), 10) 645 b = append(b, []byte{0x20}...) 646 647 if t.Hour() < 12 { 648 b = append(b, as.periodsAbbreviated[0]...) 649 } else { 650 b = append(b, as.periodsAbbreviated[1]...) 651 } 652 653 b = append(b, []byte{0x20}...) 654 655 tz, _ := t.Zone() 656 b = append(b, tz...) 657 658 return string(b) 659} 660 661// FmtTimeFull returns the full time representation of 't' for 'as' 662func (as *as) FmtTimeFull(t time.Time) string { 663 664 b := make([]byte, 0, 32) 665 666 h := t.Hour() 667 668 if h > 12 { 669 h -= 12 670 } 671 672 b = strconv.AppendInt(b, int64(h), 10) 673 b = append(b, []byte{0x2e}...) 674 675 if t.Minute() < 10 { 676 b = append(b, '0') 677 } 678 679 b = strconv.AppendInt(b, int64(t.Minute()), 10) 680 b = append(b, []byte{0x2e}...) 681 682 if t.Second() < 10 { 683 b = append(b, '0') 684 } 685 686 b = strconv.AppendInt(b, int64(t.Second()), 10) 687 b = append(b, []byte{0x20}...) 688 689 if t.Hour() < 12 { 690 b = append(b, as.periodsAbbreviated[0]...) 691 } else { 692 b = append(b, as.periodsAbbreviated[1]...) 693 } 694 695 b = append(b, []byte{0x20}...) 696 697 tz, _ := t.Zone() 698 699 if btz, ok := as.timezones[tz]; ok { 700 b = append(b, btz...) 701 } else { 702 b = append(b, tz...) 703 } 704 705 return string(b) 706} 707