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