1package to
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 to 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 'to' locale
46func New() locales.Translator {
47	return &to{
48		locale:                 "to",
49		pluralsCardinal:        []locales.PluralRule{6},
50		pluralsOrdinal:         nil,
51		pluralsRange:           nil,
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", "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", "₾", "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", "T$", "TPE", "TRL", "TRY", "TTD", "$", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "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{"", "Sān", "Fēp", "Maʻa", "ʻEpe", "Mē", "Sun", "Siu", "ʻAok", "Sep", "ʻOka", "Nōv", "Tīs"},
64		monthsNarrow:           []string{"", "S", "F", "M", "E", "M", "S", "S", "A", "S", "O", "N", "T"},
65		monthsWide:             []string{"", "Sānuali", "Fēpueli", "Maʻasi", "ʻEpeleli", "Mē", "Sune", "Siulai", "ʻAokosi", "Sepitema", "ʻOkatopa", "Nōvema", "Tīsema"},
66		daysAbbreviated:        []string{"Sāp", "Mōn", "Tūs", "Pul", "Tuʻa", "Fal", "Tok"},
67		daysNarrow:             []string{"S", "M", "T", "P", "T", "F", "T"},
68		daysShort:              []string{"Sāp", "Mōn", "Tūs", "Pul", "Tuʻa", "Fal", "Tok"},
69		daysWide:               []string{"Sāpate", "Mōnite", "Tūsite", "Pulelulu", "Tuʻapulelulu", "Falaite", "Tokonaki"},
70		periodsAbbreviated:     []string{"AM", "PM"},
71		periodsNarrow:          []string{"AM", "PM"},
72		periodsWide:            []string{"hengihengi", "efiafi"},
73		erasAbbreviated:        []string{"KM", "TS"},
74		erasNarrow:             []string{"KM", "TS"},
75		erasWide:               []string{"ki muʻa", "taʻu ʻo Sīsū"},
76		timezones:              map[string]string{"ADT": "houa fakaʻamelika-tokelau ʻatalanitiki taimi liliu", "AKDT": "houa fakaʻalasika taimi liliu", "HENOMX": "houa fakamekisikou-tokelauhihifo taimi liliu", "CLST": "houa fakasili taimi liliu", "WIT": "houa fakaʻinitonisia-hahake", "TMT": "houa fakatūkimenisitani taimi totonu", "TMST": "houa fakatūkimenisitani taimi liliu", "NZDT": "houa fakanuʻusila taimi liliu", "AKST": "houa fakaʻalasika taimi totonu", "MEZ": "houa fakaʻeulope-loto taimi totonu", "WARST": "houa fakaʻasenitina-hihifo taimi liliu", "VET": "houa fakavenesuela", "CHAST": "houa fakasatihami taimi totonu", "GFT": "houa fakakuiana-fakafalanisē", "HADT": "houa fakahauaʻi taimi liliu", "HECU": "houa fakakiupa taimi liliu", "AEDT": "houa fakaʻaositelēlia-hahake taimi liliu", "WEZ": "houa fakaʻeulope-hihifo taimi totonu", "MESZ": "houa fakaʻeulope-loto taimi liliu", "LHST": "houa fakamotuʻeikihoue taimi totonu", "ARST": "houa fakaʻasenitina taimi liliu", "SAST": "houa fakaʻafelika-tonga", "AEST": "houa fakaʻaositelēlia-hahake taimi totonu", "HNEG": "houa fakafonuamata-hahake taimi totonu", "CAT": "houa fakaʻafelika-loto", "OEZ": "houa fakaʻeulope-hahake taimi totonu", "AWDT": "houa fakaʻaositelēlia-hihifo taimi liliu", "JST": "houa fakasiapani taimi totonu", "BT": "houa fakapūtani", "IST": "houa fakaʻinitia", "HNT": "houa fakafonuaʻilofoʻou taimi totonu", "MDT": "houa fakamakau taimi liliu", "HEEG": "houa fakafonuamata-hahake taimi liliu", "EAT": "houa fakaʻafelika-hahake", "ART": "houa fakaʻasenitina taimi totonu", "CDT": "houa fakaʻamelika-tokelau loto taimi liliu", "EST": "houa fakaʻamelika-tokelau hahake taimi totonu", "HEPM": "houa fakasā-piea-mo-mikeloni taimi liliu", "HEPMX": "houa fakamekisikou-pasifika taimi liliu", "ACDT": "houa fakaʻaositelēlia-loto taimi liliu", "PDT": "houa fakaʻamelika-tokelau pasifika taimi liliu", "WAST": "houa fakaʻafelika-hihifo taimi liliu", "ACWST": "houa fakaʻaositelēlia-loto-hihifo taimi totonu", "∅∅∅": "houa fakaʻāsolesi taimi liliu", "HNPM": "houa fakasā-piea-mo-mikeloni taimi totonu", "COST": "houa fakakolomipia taimi liliu", "AWST": "houa fakaʻaositelēlia-hihifo taimi totonu", "HNPMX": "houa fakamekisikou-pasifika taimi totonu", "ACST": "houa fakaʻaositelēlia-loto taimi totonu", "HEOG": "houa fakafonuamata-hihifo taimi liliu", "HAT": "houa fakafonuaʻilofoʻou taimi liliu", "COT": "houa fakakolomipia taimi totonu", "HAST": "houa fakahauaʻi taimi totonu", "HNCU": "houa fakakiupa taimi totonu", "NZST": "houa fakanuʻusila taimi totonu", "CHADT": "houa fakasatihami taimi liliu", "CST": "houa fakaʻamelika-tokelau loto taimi totonu", "WESZ": "houa fakaʻeulope-hihifo taimi liliu", "WART": "houa fakaʻasenitina-hihifo taimi totonu", "MST": "houa fakamakau taimi totonu", "SRT": "houa fakasuliname", "OESZ": "houa fakaʻeulope-hahake taimi liliu", "GYT": "houa fakakuiana", "ECT": "houa fakaʻekuetoa", "HNOG": "houa fakafonuamata-hihifo taimi totonu", "HNNOMX": "houa fakamekisikou-tokelauhihifo taimi totonu", "AST": "houa fakaʻamelika-tokelau ʻatalanitiki taimi totonu", "WAT": "houa fakaʻafelika-hihifo taimi totonu", "MYT": "houa fakamaleisia", "SGT": "houa fakasingapoa", "HKT": "houa fakahongi-kongi taimi totonu", "LHDT": "houa fakamotuʻeikihoue taimi liliu", "UYST": "houa fakaʻulukuai taimi liliu", "BOT": "houa fakapolīvia", "ACWDT": "houa fakaʻaositelēlia-loto-hihifo taimi liliu", "CLT": "houa fakasili taimi totonu", "UYT": "houa fakaʻulukuai taimi totonu", "GMT": "houa fakakiliniuisi mālie", "JDT": "houa fakasiapani taimi liliu", "EDT": "houa fakaʻamelika-tokelau hahake taimi liliu", "HKST": "houa fakahongi-kongi taimi liliu", "WITA": "houa fakaʻinitonisia-loto", "ChST": "houa fakakamolo", "PST": "houa fakaʻamelika-tokelau pasifika taimi totonu", "WIB": "houa fakaʻinitonisia-hihifo"},
77	}
78}
79
80// Locale returns the current translators string locale
81func (to *to) Locale() string {
82	return to.locale
83}
84
85// PluralsCardinal returns the list of cardinal plural rules associated with 'to'
86func (to *to) PluralsCardinal() []locales.PluralRule {
87	return to.pluralsCardinal
88}
89
90// PluralsOrdinal returns the list of ordinal plural rules associated with 'to'
91func (to *to) PluralsOrdinal() []locales.PluralRule {
92	return to.pluralsOrdinal
93}
94
95// PluralsRange returns the list of range plural rules associated with 'to'
96func (to *to) PluralsRange() []locales.PluralRule {
97	return to.pluralsRange
98}
99
100// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'to'
101func (to *to) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
102	return locales.PluralRuleOther
103}
104
105// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'to'
106func (to *to) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
107	return locales.PluralRuleUnknown
108}
109
110// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'to'
111func (to *to) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
112	return locales.PluralRuleUnknown
113}
114
115// MonthAbbreviated returns the locales abbreviated month given the 'month' provided
116func (to *to) MonthAbbreviated(month time.Month) string {
117	return to.monthsAbbreviated[month]
118}
119
120// MonthsAbbreviated returns the locales abbreviated months
121func (to *to) MonthsAbbreviated() []string {
122	return to.monthsAbbreviated[1:]
123}
124
125// MonthNarrow returns the locales narrow month given the 'month' provided
126func (to *to) MonthNarrow(month time.Month) string {
127	return to.monthsNarrow[month]
128}
129
130// MonthsNarrow returns the locales narrow months
131func (to *to) MonthsNarrow() []string {
132	return to.monthsNarrow[1:]
133}
134
135// MonthWide returns the locales wide month given the 'month' provided
136func (to *to) MonthWide(month time.Month) string {
137	return to.monthsWide[month]
138}
139
140// MonthsWide returns the locales wide months
141func (to *to) MonthsWide() []string {
142	return to.monthsWide[1:]
143}
144
145// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
146func (to *to) WeekdayAbbreviated(weekday time.Weekday) string {
147	return to.daysAbbreviated[weekday]
148}
149
150// WeekdaysAbbreviated returns the locales abbreviated weekdays
151func (to *to) WeekdaysAbbreviated() []string {
152	return to.daysAbbreviated
153}
154
155// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
156func (to *to) WeekdayNarrow(weekday time.Weekday) string {
157	return to.daysNarrow[weekday]
158}
159
160// WeekdaysNarrow returns the locales narrow weekdays
161func (to *to) WeekdaysNarrow() []string {
162	return to.daysNarrow
163}
164
165// WeekdayShort returns the locales short weekday given the 'weekday' provided
166func (to *to) WeekdayShort(weekday time.Weekday) string {
167	return to.daysShort[weekday]
168}
169
170// WeekdaysShort returns the locales short weekdays
171func (to *to) WeekdaysShort() []string {
172	return to.daysShort
173}
174
175// WeekdayWide returns the locales wide weekday given the 'weekday' provided
176func (to *to) WeekdayWide(weekday time.Weekday) string {
177	return to.daysWide[weekday]
178}
179
180// WeekdaysWide returns the locales wide weekdays
181func (to *to) WeekdaysWide() []string {
182	return to.daysWide
183}
184
185// Decimal returns the decimal point of number
186func (to *to) Decimal() string {
187	return to.decimal
188}
189
190// Group returns the group of number
191func (to *to) Group() string {
192	return to.group
193}
194
195// Group returns the minus sign of number
196func (to *to) Minus() string {
197	return to.minus
198}
199
200// FmtNumber returns 'num' with digits/precision of 'v' for 'to' and handles both Whole and Real numbers based on 'v'
201func (to *to) FmtNumber(num float64, v uint64) string {
202
203	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
204	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
205	count := 0
206	inWhole := v == 0
207	b := make([]byte, 0, l)
208
209	for i := len(s) - 1; i >= 0; i-- {
210
211		if s[i] == '.' {
212			b = append(b, to.decimal[0])
213			inWhole = true
214			continue
215		}
216
217		if inWhole {
218			if count == 3 {
219				b = append(b, to.group[0])
220				count = 1
221			} else {
222				count++
223			}
224		}
225
226		b = append(b, s[i])
227	}
228
229	if num < 0 {
230		b = append(b, to.minus[0])
231	}
232
233	// reverse
234	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
235		b[i], b[j] = b[j], b[i]
236	}
237
238	return string(b)
239}
240
241// FmtPercent returns 'num' with digits/precision of 'v' for 'to' and handles both Whole and Real numbers based on 'v'
242// NOTE: 'num' passed into FmtPercent is assumed to be in percent already
243func (to *to) FmtPercent(num float64, v uint64) string {
244	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
245	l := len(s) + 5
246	b := make([]byte, 0, l)
247
248	for i := len(s) - 1; i >= 0; i-- {
249
250		if s[i] == '.' {
251			b = append(b, to.decimal[0])
252			continue
253		}
254
255		b = append(b, s[i])
256	}
257
258	if num < 0 {
259		b = append(b, to.minus[0])
260	}
261
262	// reverse
263	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
264		b[i], b[j] = b[j], b[i]
265	}
266
267	b = append(b, to.percentSuffix...)
268
269	b = append(b, to.percent...)
270
271	return string(b)
272}
273
274// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'to'
275func (to *to) FmtCurrency(num float64, v uint64, currency currency.Type) string {
276
277	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
278	symbol := to.currencies[currency]
279	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
280	count := 0
281	inWhole := v == 0
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, to.decimal[0])
288			inWhole = true
289			continue
290		}
291
292		if inWhole {
293			if count == 3 {
294				b = append(b, to.group[0])
295				count = 1
296			} else {
297				count++
298			}
299		}
300
301		b = append(b, s[i])
302	}
303
304	if num < 0 {
305		b = append(b, to.minus[0])
306	}
307
308	// reverse
309	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
310		b[i], b[j] = b[j], b[i]
311	}
312
313	if int(v) < 2 {
314
315		if v == 0 {
316			b = append(b, to.decimal...)
317		}
318
319		for i := 0; i < 2-int(v); i++ {
320			b = append(b, '0')
321		}
322	}
323
324	b = append(b, to.currencyPositiveSuffix...)
325
326	b = append(b, symbol...)
327
328	return string(b)
329}
330
331// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'to'
332// in accounting notation.
333func (to *to) FmtAccounting(num float64, v uint64, currency currency.Type) string {
334
335	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
336	symbol := to.currencies[currency]
337	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
338	count := 0
339	inWhole := v == 0
340	b := make([]byte, 0, l)
341
342	for i := len(s) - 1; i >= 0; i-- {
343
344		if s[i] == '.' {
345			b = append(b, to.decimal[0])
346			inWhole = true
347			continue
348		}
349
350		if inWhole {
351			if count == 3 {
352				b = append(b, to.group[0])
353				count = 1
354			} else {
355				count++
356			}
357		}
358
359		b = append(b, s[i])
360	}
361
362	if num < 0 {
363
364		b = append(b, to.minus[0])
365
366	}
367
368	// reverse
369	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
370		b[i], b[j] = b[j], b[i]
371	}
372
373	if int(v) < 2 {
374
375		if v == 0 {
376			b = append(b, to.decimal...)
377		}
378
379		for i := 0; i < 2-int(v); i++ {
380			b = append(b, '0')
381		}
382	}
383
384	if num < 0 {
385		b = append(b, to.currencyNegativeSuffix...)
386		b = append(b, symbol...)
387	} else {
388
389		b = append(b, to.currencyPositiveSuffix...)
390		b = append(b, symbol...)
391	}
392
393	return string(b)
394}
395
396// FmtDateShort returns the short date representation of 't' for 'to'
397func (to *to) FmtDateShort(t time.Time) string {
398
399	b := make([]byte, 0, 32)
400
401	b = strconv.AppendInt(b, int64(t.Day()), 10)
402	b = append(b, []byte{0x2f}...)
403	b = strconv.AppendInt(b, int64(t.Month()), 10)
404	b = append(b, []byte{0x2f}...)
405
406	if t.Year() > 9 {
407		b = append(b, strconv.Itoa(t.Year())[2:]...)
408	} else {
409		b = append(b, strconv.Itoa(t.Year())[1:]...)
410	}
411
412	return string(b)
413}
414
415// FmtDateMedium returns the medium date representation of 't' for 'to'
416func (to *to) FmtDateMedium(t time.Time) string {
417
418	b := make([]byte, 0, 32)
419
420	b = strconv.AppendInt(b, int64(t.Day()), 10)
421	b = append(b, []byte{0x20}...)
422	b = append(b, to.monthsAbbreviated[t.Month()]...)
423	b = append(b, []byte{0x20}...)
424
425	if t.Year() > 0 {
426		b = strconv.AppendInt(b, int64(t.Year()), 10)
427	} else {
428		b = strconv.AppendInt(b, int64(-t.Year()), 10)
429	}
430
431	return string(b)
432}
433
434// FmtDateLong returns the long date representation of 't' for 'to'
435func (to *to) FmtDateLong(t time.Time) string {
436
437	b := make([]byte, 0, 32)
438
439	b = strconv.AppendInt(b, int64(t.Day()), 10)
440	b = append(b, []byte{0x20}...)
441	b = append(b, to.monthsWide[t.Month()]...)
442	b = append(b, []byte{0x20}...)
443
444	if t.Year() > 0 {
445		b = strconv.AppendInt(b, int64(t.Year()), 10)
446	} else {
447		b = strconv.AppendInt(b, int64(-t.Year()), 10)
448	}
449
450	return string(b)
451}
452
453// FmtDateFull returns the full date representation of 't' for 'to'
454func (to *to) FmtDateFull(t time.Time) string {
455
456	b := make([]byte, 0, 32)
457
458	b = append(b, to.daysWide[t.Weekday()]...)
459	b = append(b, []byte{0x20}...)
460	b = strconv.AppendInt(b, int64(t.Day()), 10)
461	b = append(b, []byte{0x20}...)
462	b = append(b, to.monthsWide[t.Month()]...)
463	b = append(b, []byte{0x20}...)
464
465	if t.Year() > 0 {
466		b = strconv.AppendInt(b, int64(t.Year()), 10)
467	} else {
468		b = strconv.AppendInt(b, int64(-t.Year()), 10)
469	}
470
471	return string(b)
472}
473
474// FmtTimeShort returns the short time representation of 't' for 'to'
475func (to *to) FmtTimeShort(t time.Time) string {
476
477	b := make([]byte, 0, 32)
478
479	h := t.Hour()
480
481	if h > 12 {
482		h -= 12
483	}
484
485	b = strconv.AppendInt(b, int64(h), 10)
486	b = append(b, to.timeSeparator...)
487
488	if t.Minute() < 10 {
489		b = append(b, '0')
490	}
491
492	b = strconv.AppendInt(b, int64(t.Minute()), 10)
493	b = append(b, []byte{0x20}...)
494
495	if t.Hour() < 12 {
496		b = append(b, to.periodsAbbreviated[0]...)
497	} else {
498		b = append(b, to.periodsAbbreviated[1]...)
499	}
500
501	return string(b)
502}
503
504// FmtTimeMedium returns the medium time representation of 't' for 'to'
505func (to *to) FmtTimeMedium(t time.Time) string {
506
507	b := make([]byte, 0, 32)
508
509	h := t.Hour()
510
511	if h > 12 {
512		h -= 12
513	}
514
515	b = strconv.AppendInt(b, int64(h), 10)
516	b = append(b, to.timeSeparator...)
517
518	if t.Minute() < 10 {
519		b = append(b, '0')
520	}
521
522	b = strconv.AppendInt(b, int64(t.Minute()), 10)
523	b = append(b, to.timeSeparator...)
524
525	if t.Second() < 10 {
526		b = append(b, '0')
527	}
528
529	b = strconv.AppendInt(b, int64(t.Second()), 10)
530	b = append(b, []byte{0x20}...)
531
532	if t.Hour() < 12 {
533		b = append(b, to.periodsAbbreviated[0]...)
534	} else {
535		b = append(b, to.periodsAbbreviated[1]...)
536	}
537
538	return string(b)
539}
540
541// FmtTimeLong returns the long time representation of 't' for 'to'
542func (to *to) FmtTimeLong(t time.Time) string {
543
544	b := make([]byte, 0, 32)
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, to.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, to.timeSeparator...)
561
562	if t.Second() < 10 {
563		b = append(b, '0')
564	}
565
566	b = strconv.AppendInt(b, int64(t.Second()), 10)
567	b = append(b, []byte{0x20}...)
568
569	if t.Hour() < 12 {
570		b = append(b, to.periodsAbbreviated[0]...)
571	} else {
572		b = append(b, to.periodsAbbreviated[1]...)
573	}
574
575	b = append(b, []byte{0x20}...)
576
577	tz, _ := t.Zone()
578	b = append(b, tz...)
579
580	return string(b)
581}
582
583// FmtTimeFull returns the full time representation of 't' for 'to'
584func (to *to) FmtTimeFull(t time.Time) string {
585
586	b := make([]byte, 0, 32)
587
588	h := t.Hour()
589
590	if h > 12 {
591		h -= 12
592	}
593
594	b = strconv.AppendInt(b, int64(h), 10)
595	b = append(b, to.timeSeparator...)
596
597	if t.Minute() < 10 {
598		b = append(b, '0')
599	}
600
601	b = strconv.AppendInt(b, int64(t.Minute()), 10)
602	b = append(b, to.timeSeparator...)
603
604	if t.Second() < 10 {
605		b = append(b, '0')
606	}
607
608	b = strconv.AppendInt(b, int64(t.Second()), 10)
609	b = append(b, []byte{0x20}...)
610
611	if t.Hour() < 12 {
612		b = append(b, to.periodsAbbreviated[0]...)
613	} else {
614		b = append(b, to.periodsAbbreviated[1]...)
615	}
616
617	b = append(b, []byte{0x20}...)
618
619	tz, _ := t.Zone()
620
621	if btz, ok := to.timezones[tz]; ok {
622		b = append(b, btz...)
623	} else {
624		b = append(b, tz...)
625	}
626
627	return string(b)
628}
629