1 package hi
2
3 import (
4 "math"
5 "strconv"
6 "time"
7
8 "github.com/go-playground/locales"
9 "github.com/go-playground/locales/currency"
10 )
11
12 type hi 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
25 monthsAbbreviated []string
26 monthsNarrow []string
27 monthsWide []string
28 daysAbbreviated []string
29 daysNarrow []string
30 daysShort []string
31 daysWide []string
32 periodsAbbreviated []string
33 periodsNarrow []string
34 periodsShort []string
35 periodsWide []string
36 erasAbbreviated []string
37 erasNarrow []string
38 erasWide []string
39 timezones map[string]string
40 }
41
42
43 func New() locales.Translator {
44 return &hi{
45 locale: "hi",
46 pluralsCardinal: []locales.PluralRule{2, 6},
47 pluralsOrdinal: []locales.PluralRule{2, 3, 4, 5, 6},
48 pluralsRange: []locales.PluralRule{2, 6},
49 decimal: ".",
50 group: ",",
51 minus: "-",
52 percent: "%",
53 perMille: "‰",
54 timeSeparator: ":",
55 inifinity: "∞",
56 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", "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"},
57 monthsAbbreviated: []string{"", "जन॰", "फ़र॰", "मार्च", "अप्रैल", "मई", "जून", "जुल॰", "अग॰", "सित॰", "अक्तू॰", "नव॰", "दिस॰"},
58 monthsNarrow: []string{"", "ज", "फ़", "मा", "अ", "म", "जू", "जु", "अ", "सि", "अ", "न", "दि"},
59 monthsWide: []string{"", "जनवरी", "फ़रवरी", "मार्च", "अप्रैल", "मई", "जून", "जुलाई", "अगस्त", "सितंबर", "अक्तूबर", "नवंबर", "दिसंबर"},
60 daysAbbreviated: []string{"रवि", "सोम", "मंगल", "बुध", "गुरु", "शुक्र", "शनि"},
61 daysNarrow: []string{"र", "सो", "मं", "बु", "गु", "शु", "श"},
62 daysShort: []string{"र", "सो", "मं", "बु", "गु", "शु", "श"},
63 daysWide: []string{"रविवार", "सोमवार", "मंगलवार", "बुधवार", "गुरुवार", "शुक्रवार", "शनिवार"},
64 periodsAbbreviated: []string{"am", "pm"},
65 periodsNarrow: []string{"am", "pm"},
66 periodsWide: []string{"am", "pm"},
67 erasAbbreviated: []string{"ईसा-पूर्व", "ईस्वी"},
68 erasNarrow: []string{"", ""},
69 erasWide: []string{"ईसा-पूर्व", "ईसवी सन"},
70 timezones: map[string]string{"ACDT": "ऑस्\u200dट्रेलियाई केंद्रीय डेलाइट समय", "ACST": "ऑस्\u200dट्रेलियाई केंद्रीय मानक समय", "ACWDT": "ऑस्\u200dट्रेलियाई केंद्रीय पश्चिमी डेलाइट समय", "ACWST": "ऑस्\u200dट्रेलियाई केंद्रीय पश्चिमी मानक समय", "ADT": "अटलांटिक डेलाइट समय", "AEDT": "ऑस्\u200dट्रेलियाई पूर्वी डेलाइट समय", "AEST": "ऑस्\u200dट्रेलियाई पूर्वी मानक समय", "AKDT": "अलास्\u200dका डेलाइट समय", "AKST": "अलास्\u200dका मानक समय", "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": "मध्\u200dय यूरोपीय ग्रीष्\u200dमकालीन समय", "MEZ": "मध्य यूरोपीय मानक समय", "MST": "उत्तरी अमेरिकी माउंटेन मानक समय", "MYT": "मलेशिया समय", "NZDT": "न्यूज़ीलैंड डेलाइट समय", "NZST": "न्यूज़ीलैंड मानक समय", "OESZ": "पूर्वी यूरोपीय ग्रीष्मकालीन समय", "OEZ": "पूर्वी यूरोपीय मानक समय", "PDT": "उत्तरी अमेरिकी प्रशांत डेलाइट समय", "PST": "उत्तरी अमेरिकी प्रशांत मानक समय", "SAST": "दक्षिण अफ़्रीका मानक समय", "SGT": "सिंगापुर समय", "SRT": "सूरीनाम समय", "TMST": "तुर्कमेनिस्तान ग्रीष्मकालीन समय", "TMT": "तुर्कमेनिस्तान मानक समय", "UYST": "उरुग्वे ग्रीष्मकालीन समय", "UYT": "उरुग्वे मानक समय", "VET": "वेनेज़ुएला समय", "WARST": "पश्चिमी अर्जेंटीना ग्रीष्मकालीन समय", "WART": "पश्चिमी अर्जेंटीना मानक समय", "WAST": "पश्चिम अफ़्रीका ग्रीष्मकालीन समय", "WAT": "पश्चिम अफ़्रीका मानक समय", "WESZ": "पश्चिमी यूरोपीय ग्रीष्\u200dमकालीन समय", "WEZ": "पश्चिमी यूरोपीय मानक समय", "WIB": "पश्चिमी इंडोनेशिया समय", "WIT": "पूर्वी इंडोनेशिया समय", "WITA": "मध्य इंडोनेशिया समय", "∅∅∅": "ब्राज़ीलिया ग्रीष्मकालीन समय"},
71 }
72 }
73
74
75 func (hi *hi) Locale() string {
76 return hi.locale
77 }
78
79
80 func (hi *hi) PluralsCardinal() []locales.PluralRule {
81 return hi.pluralsCardinal
82 }
83
84
85 func (hi *hi) PluralsOrdinal() []locales.PluralRule {
86 return hi.pluralsOrdinal
87 }
88
89
90 func (hi *hi) PluralsRange() []locales.PluralRule {
91 return hi.pluralsRange
92 }
93
94
95 func (hi *hi) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
96
97 n := math.Abs(num)
98 i := int64(n)
99
100 if (i == 0) || (n == 1) {
101 return locales.PluralRuleOne
102 }
103
104 return locales.PluralRuleOther
105 }
106
107
108 func (hi *hi) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
109
110 n := math.Abs(num)
111
112 if n == 1 {
113 return locales.PluralRuleOne
114 } else if n == 2 || n == 3 {
115 return locales.PluralRuleTwo
116 } else if n == 4 {
117 return locales.PluralRuleFew
118 } else if n == 6 {
119 return locales.PluralRuleMany
120 }
121
122 return locales.PluralRuleOther
123 }
124
125
126 func (hi *hi) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
127
128 start := hi.CardinalPluralRule(num1, v1)
129 end := hi.CardinalPluralRule(num2, v2)
130
131 if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
132 return locales.PluralRuleOne
133 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
134 return locales.PluralRuleOther
135 }
136
137 return locales.PluralRuleOther
138
139 }
140
141
142 func (hi *hi) MonthAbbreviated(month time.Month) string {
143 return hi.monthsAbbreviated[month]
144 }
145
146
147 func (hi *hi) MonthsAbbreviated() []string {
148 return hi.monthsAbbreviated[1:]
149 }
150
151
152 func (hi *hi) MonthNarrow(month time.Month) string {
153 return hi.monthsNarrow[month]
154 }
155
156
157 func (hi *hi) MonthsNarrow() []string {
158 return hi.monthsNarrow[1:]
159 }
160
161
162 func (hi *hi) MonthWide(month time.Month) string {
163 return hi.monthsWide[month]
164 }
165
166
167 func (hi *hi) MonthsWide() []string {
168 return hi.monthsWide[1:]
169 }
170
171
172 func (hi *hi) WeekdayAbbreviated(weekday time.Weekday) string {
173 return hi.daysAbbreviated[weekday]
174 }
175
176
177 func (hi *hi) WeekdaysAbbreviated() []string {
178 return hi.daysAbbreviated
179 }
180
181
182 func (hi *hi) WeekdayNarrow(weekday time.Weekday) string {
183 return hi.daysNarrow[weekday]
184 }
185
186
187 func (hi *hi) WeekdaysNarrow() []string {
188 return hi.daysNarrow
189 }
190
191
192 func (hi *hi) WeekdayShort(weekday time.Weekday) string {
193 return hi.daysShort[weekday]
194 }
195
196
197 func (hi *hi) WeekdaysShort() []string {
198 return hi.daysShort
199 }
200
201
202 func (hi *hi) WeekdayWide(weekday time.Weekday) string {
203 return hi.daysWide[weekday]
204 }
205
206
207 func (hi *hi) WeekdaysWide() []string {
208 return hi.daysWide
209 }
210
211
212 func (hi *hi) Decimal() string {
213 return hi.decimal
214 }
215
216
217 func (hi *hi) Group() string {
218 return hi.group
219 }
220
221
222 func (hi *hi) Minus() string {
223 return hi.minus
224 }
225
226
227 func (hi *hi) FmtNumber(num float64, v uint64) string {
228
229 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
230 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
231 count := 0
232 inWhole := v == 0
233 inSecondary := false
234 groupThreshold := 3
235
236 b := make([]byte, 0, l)
237
238 for i := len(s) - 1; i >= 0; i-- {
239
240 if s[i] == '.' {
241 b = append(b, hi.decimal[0])
242 inWhole = true
243 continue
244 }
245
246 if inWhole {
247
248 if count == groupThreshold {
249 b = append(b, hi.group[0])
250 count = 1
251
252 if !inSecondary {
253 inSecondary = true
254 groupThreshold = 2
255 }
256 } else {
257 count++
258 }
259 }
260
261 b = append(b, s[i])
262 }
263
264 if num < 0 {
265 b = append(b, hi.minus[0])
266 }
267
268
269 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
270 b[i], b[j] = b[j], b[i]
271 }
272
273 return string(b)
274 }
275
276
277
278 func (hi *hi) FmtPercent(num float64, v uint64) string {
279 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
280 l := len(s) + 3
281 b := make([]byte, 0, l)
282
283 for i := len(s) - 1; i >= 0; i-- {
284
285 if s[i] == '.' {
286 b = append(b, hi.decimal[0])
287 continue
288 }
289
290 b = append(b, s[i])
291 }
292
293 if num < 0 {
294 b = append(b, hi.minus[0])
295 }
296
297
298 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
299 b[i], b[j] = b[j], b[i]
300 }
301
302 b = append(b, hi.percent...)
303
304 return string(b)
305 }
306
307
308 func (hi *hi) FmtCurrency(num float64, v uint64, currency currency.Type) string {
309
310 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
311 symbol := hi.currencies[currency]
312 l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
313 count := 0
314 inWhole := v == 0
315 inSecondary := false
316 groupThreshold := 3
317
318 b := make([]byte, 0, l)
319
320 for i := len(s) - 1; i >= 0; i-- {
321
322 if s[i] == '.' {
323 b = append(b, hi.decimal[0])
324 inWhole = true
325 continue
326 }
327
328 if inWhole {
329
330 if count == groupThreshold {
331 b = append(b, hi.group[0])
332 count = 1
333
334 if !inSecondary {
335 inSecondary = true
336 groupThreshold = 2
337 }
338 } else {
339 count++
340 }
341 }
342
343 b = append(b, s[i])
344 }
345
346 for j := len(symbol) - 1; j >= 0; j-- {
347 b = append(b, symbol[j])
348 }
349
350 if num < 0 {
351 b = append(b, hi.minus[0])
352 }
353
354
355 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
356 b[i], b[j] = b[j], b[i]
357 }
358
359 if int(v) < 2 {
360
361 if v == 0 {
362 b = append(b, hi.decimal...)
363 }
364
365 for i := 0; i < 2-int(v); i++ {
366 b = append(b, '0')
367 }
368 }
369
370 return string(b)
371 }
372
373
374
375 func (hi *hi) FmtAccounting(num float64, v uint64, currency currency.Type) string {
376
377 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
378 symbol := hi.currencies[currency]
379 l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
380 count := 0
381 inWhole := v == 0
382 inSecondary := false
383 groupThreshold := 3
384
385 b := make([]byte, 0, l)
386
387 for i := len(s) - 1; i >= 0; i-- {
388
389 if s[i] == '.' {
390 b = append(b, hi.decimal[0])
391 inWhole = true
392 continue
393 }
394
395 if inWhole {
396
397 if count == groupThreshold {
398 b = append(b, hi.group[0])
399 count = 1
400
401 if !inSecondary {
402 inSecondary = true
403 groupThreshold = 2
404 }
405 } else {
406 count++
407 }
408 }
409
410 b = append(b, s[i])
411 }
412
413 if num < 0 {
414
415 for j := len(symbol) - 1; j >= 0; j-- {
416 b = append(b, symbol[j])
417 }
418
419 b = append(b, hi.minus[0])
420
421 } else {
422
423 for j := len(symbol) - 1; j >= 0; j-- {
424 b = append(b, symbol[j])
425 }
426
427 }
428
429
430 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
431 b[i], b[j] = b[j], b[i]
432 }
433
434 if int(v) < 2 {
435
436 if v == 0 {
437 b = append(b, hi.decimal...)
438 }
439
440 for i := 0; i < 2-int(v); i++ {
441 b = append(b, '0')
442 }
443 }
444
445 return string(b)
446 }
447
448
449 func (hi *hi) FmtDateShort(t time.Time) string {
450
451 b := make([]byte, 0, 32)
452
453 b = strconv.AppendInt(b, int64(t.Day()), 10)
454 b = append(b, []byte{0x2f}...)
455 b = strconv.AppendInt(b, int64(t.Month()), 10)
456 b = append(b, []byte{0x2f}...)
457
458 if t.Year() > 9 {
459 b = append(b, strconv.Itoa(t.Year())[2:]...)
460 } else {
461 b = append(b, strconv.Itoa(t.Year())[1:]...)
462 }
463
464 return string(b)
465 }
466
467
468 func (hi *hi) FmtDateMedium(t time.Time) string {
469
470 b := make([]byte, 0, 32)
471
472 b = strconv.AppendInt(b, int64(t.Day()), 10)
473 b = append(b, []byte{0x20}...)
474 b = append(b, hi.monthsAbbreviated[t.Month()]...)
475 b = append(b, []byte{0x20}...)
476
477 if t.Year() > 0 {
478 b = strconv.AppendInt(b, int64(t.Year()), 10)
479 } else {
480 b = strconv.AppendInt(b, int64(-t.Year()), 10)
481 }
482
483 return string(b)
484 }
485
486
487 func (hi *hi) FmtDateLong(t time.Time) string {
488
489 b := make([]byte, 0, 32)
490
491 b = strconv.AppendInt(b, int64(t.Day()), 10)
492 b = append(b, []byte{0x20}...)
493 b = append(b, hi.monthsWide[t.Month()]...)
494 b = append(b, []byte{0x20}...)
495
496 if t.Year() > 0 {
497 b = strconv.AppendInt(b, int64(t.Year()), 10)
498 } else {
499 b = strconv.AppendInt(b, int64(-t.Year()), 10)
500 }
501
502 return string(b)
503 }
504
505
506 func (hi *hi) FmtDateFull(t time.Time) string {
507
508 b := make([]byte, 0, 32)
509
510 b = append(b, hi.daysWide[t.Weekday()]...)
511 b = append(b, []byte{0x2c, 0x20}...)
512 b = strconv.AppendInt(b, int64(t.Day()), 10)
513 b = append(b, []byte{0x20}...)
514 b = append(b, hi.monthsWide[t.Month()]...)
515 b = append(b, []byte{0x20}...)
516
517 if t.Year() > 0 {
518 b = strconv.AppendInt(b, int64(t.Year()), 10)
519 } else {
520 b = strconv.AppendInt(b, int64(-t.Year()), 10)
521 }
522
523 return string(b)
524 }
525
526
527 func (hi *hi) FmtTimeShort(t time.Time) string {
528
529 b := make([]byte, 0, 32)
530
531 h := t.Hour()
532
533 if h > 12 {
534 h -= 12
535 }
536
537 b = strconv.AppendInt(b, int64(h), 10)
538 b = append(b, hi.timeSeparator...)
539
540 if t.Minute() < 10 {
541 b = append(b, '0')
542 }
543
544 b = strconv.AppendInt(b, int64(t.Minute()), 10)
545 b = append(b, []byte{0x20}...)
546
547 if t.Hour() < 12 {
548 b = append(b, hi.periodsAbbreviated[0]...)
549 } else {
550 b = append(b, hi.periodsAbbreviated[1]...)
551 }
552
553 return string(b)
554 }
555
556
557 func (hi *hi) FmtTimeMedium(t time.Time) string {
558
559 b := make([]byte, 0, 32)
560
561 h := t.Hour()
562
563 if h > 12 {
564 h -= 12
565 }
566
567 b = strconv.AppendInt(b, int64(h), 10)
568 b = append(b, hi.timeSeparator...)
569
570 if t.Minute() < 10 {
571 b = append(b, '0')
572 }
573
574 b = strconv.AppendInt(b, int64(t.Minute()), 10)
575 b = append(b, hi.timeSeparator...)
576
577 if t.Second() < 10 {
578 b = append(b, '0')
579 }
580
581 b = strconv.AppendInt(b, int64(t.Second()), 10)
582 b = append(b, []byte{0x20}...)
583
584 if t.Hour() < 12 {
585 b = append(b, hi.periodsAbbreviated[0]...)
586 } else {
587 b = append(b, hi.periodsAbbreviated[1]...)
588 }
589
590 return string(b)
591 }
592
593
594 func (hi *hi) FmtTimeLong(t time.Time) string {
595
596 b := make([]byte, 0, 32)
597
598 h := t.Hour()
599
600 if h > 12 {
601 h -= 12
602 }
603
604 b = strconv.AppendInt(b, int64(h), 10)
605 b = append(b, hi.timeSeparator...)
606
607 if t.Minute() < 10 {
608 b = append(b, '0')
609 }
610
611 b = strconv.AppendInt(b, int64(t.Minute()), 10)
612 b = append(b, hi.timeSeparator...)
613
614 if t.Second() < 10 {
615 b = append(b, '0')
616 }
617
618 b = strconv.AppendInt(b, int64(t.Second()), 10)
619 b = append(b, []byte{0x20}...)
620
621 if t.Hour() < 12 {
622 b = append(b, hi.periodsAbbreviated[0]...)
623 } else {
624 b = append(b, hi.periodsAbbreviated[1]...)
625 }
626
627 b = append(b, []byte{0x20}...)
628
629 tz, _ := t.Zone()
630 b = append(b, tz...)
631
632 return string(b)
633 }
634
635
636 func (hi *hi) FmtTimeFull(t time.Time) string {
637
638 b := make([]byte, 0, 32)
639
640 h := t.Hour()
641
642 if h > 12 {
643 h -= 12
644 }
645
646 b = strconv.AppendInt(b, int64(h), 10)
647 b = append(b, hi.timeSeparator...)
648
649 if t.Minute() < 10 {
650 b = append(b, '0')
651 }
652
653 b = strconv.AppendInt(b, int64(t.Minute()), 10)
654 b = append(b, hi.timeSeparator...)
655
656 if t.Second() < 10 {
657 b = append(b, '0')
658 }
659
660 b = strconv.AppendInt(b, int64(t.Second()), 10)
661 b = append(b, []byte{0x20}...)
662
663 if t.Hour() < 12 {
664 b = append(b, hi.periodsAbbreviated[0]...)
665 } else {
666 b = append(b, hi.periodsAbbreviated[1]...)
667 }
668
669 b = append(b, []byte{0x20}...)
670
671 tz, _ := t.Zone()
672
673 if btz, ok := hi.timezones[tz]; ok {
674 b = append(b, btz...)
675 } else {
676 b = append(b, tz...)
677 }
678
679 return string(b)
680 }
681
View as plain text