1 package th
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 th 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 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
45 func New() locales.Translator {
46 return &th{
47 locale: "th",
48 pluralsCardinal: []locales.PluralRule{6},
49 pluralsOrdinal: []locales.PluralRule{6},
50 pluralsRange: []locales.PluralRule{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", "AU$", "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", "US$", "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{"a", "p"},
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
79 func (th *th) Locale() string {
80 return th.locale
81 }
82
83
84 func (th *th) PluralsCardinal() []locales.PluralRule {
85 return th.pluralsCardinal
86 }
87
88
89 func (th *th) PluralsOrdinal() []locales.PluralRule {
90 return th.pluralsOrdinal
91 }
92
93
94 func (th *th) PluralsRange() []locales.PluralRule {
95 return th.pluralsRange
96 }
97
98
99 func (th *th) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
100 return locales.PluralRuleOther
101 }
102
103
104 func (th *th) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
105 return locales.PluralRuleOther
106 }
107
108
109 func (th *th) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
110 return locales.PluralRuleOther
111 }
112
113
114 func (th *th) MonthAbbreviated(month time.Month) string {
115 return th.monthsAbbreviated[month]
116 }
117
118
119 func (th *th) MonthsAbbreviated() []string {
120 return th.monthsAbbreviated[1:]
121 }
122
123
124 func (th *th) MonthNarrow(month time.Month) string {
125 return th.monthsNarrow[month]
126 }
127
128
129 func (th *th) MonthsNarrow() []string {
130 return th.monthsNarrow[1:]
131 }
132
133
134 func (th *th) MonthWide(month time.Month) string {
135 return th.monthsWide[month]
136 }
137
138
139 func (th *th) MonthsWide() []string {
140 return th.monthsWide[1:]
141 }
142
143
144 func (th *th) WeekdayAbbreviated(weekday time.Weekday) string {
145 return th.daysAbbreviated[weekday]
146 }
147
148
149 func (th *th) WeekdaysAbbreviated() []string {
150 return th.daysAbbreviated
151 }
152
153
154 func (th *th) WeekdayNarrow(weekday time.Weekday) string {
155 return th.daysNarrow[weekday]
156 }
157
158
159 func (th *th) WeekdaysNarrow() []string {
160 return th.daysNarrow
161 }
162
163
164 func (th *th) WeekdayShort(weekday time.Weekday) string {
165 return th.daysShort[weekday]
166 }
167
168
169 func (th *th) WeekdaysShort() []string {
170 return th.daysShort
171 }
172
173
174 func (th *th) WeekdayWide(weekday time.Weekday) string {
175 return th.daysWide[weekday]
176 }
177
178
179 func (th *th) WeekdaysWide() []string {
180 return th.daysWide
181 }
182
183
184 func (th *th) Decimal() string {
185 return th.decimal
186 }
187
188
189 func (th *th) Group() string {
190 return th.group
191 }
192
193
194 func (th *th) Minus() string {
195 return th.minus
196 }
197
198
199 func (th *th) FmtNumber(num float64, v uint64) string {
200
201 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
202 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
203 count := 0
204 inWhole := v == 0
205 b := make([]byte, 0, l)
206
207 for i := len(s) - 1; i >= 0; i-- {
208
209 if s[i] == '.' {
210 b = append(b, th.decimal[0])
211 inWhole = true
212 continue
213 }
214
215 if inWhole {
216 if count == 3 {
217 b = append(b, th.group[0])
218 count = 1
219 } else {
220 count++
221 }
222 }
223
224 b = append(b, s[i])
225 }
226
227 if num < 0 {
228 b = append(b, th.minus[0])
229 }
230
231
232 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
233 b[i], b[j] = b[j], b[i]
234 }
235
236 return string(b)
237 }
238
239
240
241 func (th *th) FmtPercent(num float64, v uint64) string {
242 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
243 l := len(s) + 3
244 b := make([]byte, 0, l)
245
246 for i := len(s) - 1; i >= 0; i-- {
247
248 if s[i] == '.' {
249 b = append(b, th.decimal[0])
250 continue
251 }
252
253 b = append(b, s[i])
254 }
255
256 if num < 0 {
257 b = append(b, th.minus[0])
258 }
259
260
261 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
262 b[i], b[j] = b[j], b[i]
263 }
264
265 b = append(b, th.percent...)
266
267 return string(b)
268 }
269
270
271 func (th *th) FmtCurrency(num float64, v uint64, currency currency.Type) string {
272
273 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
274 symbol := th.currencies[currency]
275 l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
276 count := 0
277 inWhole := v == 0
278 b := make([]byte, 0, l)
279
280 for i := len(s) - 1; i >= 0; i-- {
281
282 if s[i] == '.' {
283 b = append(b, th.decimal[0])
284 inWhole = true
285 continue
286 }
287
288 if inWhole {
289 if count == 3 {
290 b = append(b, th.group[0])
291 count = 1
292 } else {
293 count++
294 }
295 }
296
297 b = append(b, s[i])
298 }
299
300 for j := len(symbol) - 1; j >= 0; j-- {
301 b = append(b, symbol[j])
302 }
303
304 if num < 0 {
305 b = append(b, th.minus[0])
306 }
307
308
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, th.decimal...)
317 }
318
319 for i := 0; i < 2-int(v); i++ {
320 b = append(b, '0')
321 }
322 }
323
324 return string(b)
325 }
326
327
328
329 func (th *th) FmtAccounting(num float64, v uint64, currency currency.Type) string {
330
331 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
332 symbol := th.currencies[currency]
333 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
334 count := 0
335 inWhole := v == 0
336 b := make([]byte, 0, l)
337
338 for i := len(s) - 1; i >= 0; i-- {
339
340 if s[i] == '.' {
341 b = append(b, th.decimal[0])
342 inWhole = true
343 continue
344 }
345
346 if inWhole {
347 if count == 3 {
348 b = append(b, th.group[0])
349 count = 1
350 } else {
351 count++
352 }
353 }
354
355 b = append(b, s[i])
356 }
357
358 if num < 0 {
359
360 for j := len(symbol) - 1; j >= 0; j-- {
361 b = append(b, symbol[j])
362 }
363
364 b = append(b, th.currencyNegativePrefix[0])
365
366 } else {
367
368 for j := len(symbol) - 1; j >= 0; j-- {
369 b = append(b, symbol[j])
370 }
371
372 }
373
374
375 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
376 b[i], b[j] = b[j], b[i]
377 }
378
379 if int(v) < 2 {
380
381 if v == 0 {
382 b = append(b, th.decimal...)
383 }
384
385 for i := 0; i < 2-int(v); i++ {
386 b = append(b, '0')
387 }
388 }
389
390 if num < 0 {
391 b = append(b, th.currencyNegativeSuffix...)
392 }
393
394 return string(b)
395 }
396
397
398 func (th *th) FmtDateShort(t time.Time) string {
399
400 b := make([]byte, 0, 32)
401
402 b = strconv.AppendInt(b, int64(t.Day()), 10)
403 b = append(b, []byte{0x2f}...)
404 b = strconv.AppendInt(b, int64(t.Month()), 10)
405 b = append(b, []byte{0x2f}...)
406
407 if t.Year() > 9 {
408 b = append(b, strconv.Itoa(t.Year())[2:]...)
409 } else {
410 b = append(b, strconv.Itoa(t.Year())[1:]...)
411 }
412
413 return string(b)
414 }
415
416
417 func (th *th) FmtDateMedium(t time.Time) string {
418
419 b := make([]byte, 0, 32)
420
421 b = strconv.AppendInt(b, int64(t.Day()), 10)
422 b = append(b, []byte{0x20}...)
423 b = append(b, th.monthsAbbreviated[t.Month()]...)
424 b = append(b, []byte{0x20}...)
425
426 if t.Year() > 0 {
427 b = strconv.AppendInt(b, int64(t.Year()), 10)
428 } else {
429 b = strconv.AppendInt(b, int64(-t.Year()), 10)
430 }
431
432 return string(b)
433 }
434
435
436 func (th *th) FmtDateLong(t time.Time) string {
437
438 b := make([]byte, 0, 32)
439
440 b = strconv.AppendInt(b, int64(t.Day()), 10)
441 b = append(b, []byte{0x20}...)
442 b = append(b, th.monthsWide[t.Month()]...)
443 b = append(b, []byte{0x20}...)
444
445 if t.Year() < 0 {
446 b = append(b, th.erasAbbreviated[0]...)
447 } else {
448 b = append(b, th.erasAbbreviated[1]...)
449 }
450
451 b = append(b, []byte{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
463 func (th *th) FmtDateFull(t time.Time) string {
464
465 b := make([]byte, 0, 32)
466
467 b = append(b, th.daysWide[t.Weekday()]...)
468 b = append(b, []byte{0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0xe0, 0xb9, 0x88, 0x20}...)
469 b = strconv.AppendInt(b, int64(t.Day()), 10)
470 b = append(b, []byte{0x20}...)
471 b = append(b, th.monthsWide[t.Month()]...)
472 b = append(b, []byte{0x20}...)
473
474 if t.Year() < 0 {
475 b = append(b, th.erasWide[0]...)
476 } else {
477 b = append(b, th.erasWide[1]...)
478 }
479
480 b = append(b, []byte{0x20}...)
481
482 if t.Year() > 0 {
483 b = strconv.AppendInt(b, int64(t.Year()), 10)
484 } else {
485 b = strconv.AppendInt(b, int64(-t.Year()), 10)
486 }
487
488 return string(b)
489 }
490
491
492 func (th *th) FmtTimeShort(t time.Time) string {
493
494 b := make([]byte, 0, 32)
495
496 if t.Hour() < 10 {
497 b = append(b, '0')
498 }
499
500 b = strconv.AppendInt(b, int64(t.Hour()), 10)
501 b = append(b, th.timeSeparator...)
502
503 if t.Minute() < 10 {
504 b = append(b, '0')
505 }
506
507 b = strconv.AppendInt(b, int64(t.Minute()), 10)
508
509 return string(b)
510 }
511
512
513 func (th *th) FmtTimeMedium(t time.Time) string {
514
515 b := make([]byte, 0, 32)
516
517 if t.Hour() < 10 {
518 b = append(b, '0')
519 }
520
521 b = strconv.AppendInt(b, int64(t.Hour()), 10)
522 b = append(b, th.timeSeparator...)
523
524 if t.Minute() < 10 {
525 b = append(b, '0')
526 }
527
528 b = strconv.AppendInt(b, int64(t.Minute()), 10)
529 b = append(b, th.timeSeparator...)
530
531 if t.Second() < 10 {
532 b = append(b, '0')
533 }
534
535 b = strconv.AppendInt(b, int64(t.Second()), 10)
536
537 return string(b)
538 }
539
540
541 func (th *th) FmtTimeLong(t time.Time) string {
542
543 b := make([]byte, 0, 32)
544
545 b = strconv.AppendInt(b, int64(t.Hour()), 10)
546 b = append(b, []byte{0x20, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0xac, 0xe0, 0xb8, 0xb4, 0xe0, 0xb8, 0x81, 0xe0, 0xb8, 0xb2, 0x20}...)
547
548 if t.Minute() < 10 {
549 b = append(b, '0')
550 }
551
552 b = strconv.AppendInt(b, int64(t.Minute()), 10)
553 b = append(b, []byte{0x20, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0x20}...)
554
555 if t.Second() < 10 {
556 b = append(b, '0')
557 }
558
559 b = strconv.AppendInt(b, int64(t.Second()), 10)
560 b = append(b, []byte{0x20, 0xe0, 0xb8, 0xa7, 0xe0, 0xb8, 0xb4, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0x20}...)
561
562 tz, _ := t.Zone()
563 b = append(b, tz...)
564
565 return string(b)
566 }
567
568
569 func (th *th) FmtTimeFull(t time.Time) string {
570
571 b := make([]byte, 0, 32)
572
573 b = strconv.AppendInt(b, int64(t.Hour()), 10)
574 b = append(b, []byte{0x20, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0xac, 0xe0, 0xb8, 0xb4, 0xe0, 0xb8, 0x81, 0xe0, 0xb8, 0xb2, 0x20}...)
575
576 if t.Minute() < 10 {
577 b = append(b, '0')
578 }
579
580 b = strconv.AppendInt(b, int64(t.Minute()), 10)
581 b = append(b, []byte{0x20, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0x20}...)
582
583 if t.Second() < 10 {
584 b = append(b, '0')
585 }
586
587 b = strconv.AppendInt(b, int64(t.Second()), 10)
588 b = append(b, []byte{0x20, 0xe0, 0xb8, 0xa7, 0xe0, 0xb8, 0xb4, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0x20}...)
589
590 tz, _ := t.Zone()
591
592 if btz, ok := th.timezones[tz]; ok {
593 b = append(b, btz...)
594 } else {
595 b = append(b, tz...)
596 }
597
598 return string(b)
599 }
600
View as plain text