1 package sd
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 sd 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 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
45 func New() locales.Translator {
46 return &sd{
47 locale: "sd",
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", "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", "Rs", "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", "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 currencyPositivePrefix: " ",
60 currencyNegativePrefix: " ",
61 monthsAbbreviated: []string{"", "جنوري", "فيبروري", "مارچ", "اپريل", "مئي", "جون", "جولاءِ", "آگسٽ", "سيپٽمبر", "آڪٽوبر", "نومبر", "ڊسمبر"},
62 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
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{"BC", "CD"},
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 (sd *sd) Locale() string {
80 return sd.locale
81 }
82
83
84 func (sd *sd) PluralsCardinal() []locales.PluralRule {
85 return sd.pluralsCardinal
86 }
87
88
89 func (sd *sd) PluralsOrdinal() []locales.PluralRule {
90 return sd.pluralsOrdinal
91 }
92
93
94 func (sd *sd) PluralsRange() []locales.PluralRule {
95 return sd.pluralsRange
96 }
97
98
99 func (sd *sd) 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
111 func (sd *sd) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
112 return locales.PluralRuleOther
113 }
114
115
116 func (sd *sd) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
117
118 start := sd.CardinalPluralRule(num1, v1)
119 end := sd.CardinalPluralRule(num2, v2)
120
121 if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
122 return locales.PluralRuleOther
123 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
124 return locales.PluralRuleOther
125 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
126 return locales.PluralRuleOne
127 }
128
129 return locales.PluralRuleOther
130
131 }
132
133
134 func (sd *sd) MonthAbbreviated(month time.Month) string {
135 return sd.monthsAbbreviated[month]
136 }
137
138
139 func (sd *sd) MonthsAbbreviated() []string {
140 return sd.monthsAbbreviated[1:]
141 }
142
143
144 func (sd *sd) MonthNarrow(month time.Month) string {
145 return sd.monthsNarrow[month]
146 }
147
148
149 func (sd *sd) MonthsNarrow() []string {
150 return sd.monthsNarrow[1:]
151 }
152
153
154 func (sd *sd) MonthWide(month time.Month) string {
155 return sd.monthsWide[month]
156 }
157
158
159 func (sd *sd) MonthsWide() []string {
160 return sd.monthsWide[1:]
161 }
162
163
164 func (sd *sd) WeekdayAbbreviated(weekday time.Weekday) string {
165 return sd.daysAbbreviated[weekday]
166 }
167
168
169 func (sd *sd) WeekdaysAbbreviated() []string {
170 return sd.daysAbbreviated
171 }
172
173
174 func (sd *sd) WeekdayNarrow(weekday time.Weekday) string {
175 return sd.daysNarrow[weekday]
176 }
177
178
179 func (sd *sd) WeekdaysNarrow() []string {
180 return sd.daysNarrow
181 }
182
183
184 func (sd *sd) WeekdayShort(weekday time.Weekday) string {
185 return sd.daysShort[weekday]
186 }
187
188
189 func (sd *sd) WeekdaysShort() []string {
190 return sd.daysShort
191 }
192
193
194 func (sd *sd) WeekdayWide(weekday time.Weekday) string {
195 return sd.daysWide[weekday]
196 }
197
198
199 func (sd *sd) WeekdaysWide() []string {
200 return sd.daysWide
201 }
202
203
204 func (sd *sd) Decimal() string {
205 return sd.decimal
206 }
207
208
209 func (sd *sd) Group() string {
210 return sd.group
211 }
212
213
214 func (sd *sd) Minus() string {
215 return sd.minus
216 }
217
218
219 func (sd *sd) FmtNumber(num float64, v uint64) string {
220
221 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
222 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
223 count := 0
224 inWhole := v == 0
225 b := make([]byte, 0, l)
226
227 for i := len(s) - 1; i >= 0; i-- {
228
229 if s[i] == '.' {
230 b = append(b, sd.decimal[0])
231 inWhole = true
232 continue
233 }
234
235 if inWhole {
236 if count == 3 {
237 b = append(b, sd.group[0])
238 count = 1
239 } else {
240 count++
241 }
242 }
243
244 b = append(b, s[i])
245 }
246
247 if num < 0 {
248 b = append(b, sd.minus[0])
249 }
250
251
252 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
253 b[i], b[j] = b[j], b[i]
254 }
255
256 return string(b)
257 }
258
259
260
261 func (sd *sd) FmtPercent(num float64, v uint64) string {
262 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
263 l := len(s) + 3
264 b := make([]byte, 0, l)
265
266 for i := len(s) - 1; i >= 0; i-- {
267
268 if s[i] == '.' {
269 b = append(b, sd.decimal[0])
270 continue
271 }
272
273 b = append(b, s[i])
274 }
275
276 if num < 0 {
277 b = append(b, sd.minus[0])
278 }
279
280
281 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
282 b[i], b[j] = b[j], b[i]
283 }
284
285 b = append(b, sd.percent...)
286
287 return string(b)
288 }
289
290
291 func (sd *sd) FmtCurrency(num float64, v uint64, currency currency.Type) string {
292
293 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
294 symbol := sd.currencies[currency]
295 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
296 count := 0
297 inWhole := v == 0
298 b := make([]byte, 0, l)
299
300 for i := len(s) - 1; i >= 0; i-- {
301
302 if s[i] == '.' {
303 b = append(b, sd.decimal[0])
304 inWhole = true
305 continue
306 }
307
308 if inWhole {
309 if count == 3 {
310 b = append(b, sd.group[0])
311 count = 1
312 } else {
313 count++
314 }
315 }
316
317 b = append(b, s[i])
318 }
319
320 for j := len(symbol) - 1; j >= 0; j-- {
321 b = append(b, symbol[j])
322 }
323
324 for j := len(sd.currencyPositivePrefix) - 1; j >= 0; j-- {
325 b = append(b, sd.currencyPositivePrefix[j])
326 }
327
328 if num < 0 {
329 b = append(b, sd.minus[0])
330 }
331
332
333 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
334 b[i], b[j] = b[j], b[i]
335 }
336
337 if int(v) < 2 {
338
339 if v == 0 {
340 b = append(b, sd.decimal...)
341 }
342
343 for i := 0; i < 2-int(v); i++ {
344 b = append(b, '0')
345 }
346 }
347
348 return string(b)
349 }
350
351
352
353 func (sd *sd) FmtAccounting(num float64, v uint64, currency currency.Type) string {
354
355 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
356 symbol := sd.currencies[currency]
357 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
358 count := 0
359 inWhole := v == 0
360 b := make([]byte, 0, l)
361
362 for i := len(s) - 1; i >= 0; i-- {
363
364 if s[i] == '.' {
365 b = append(b, sd.decimal[0])
366 inWhole = true
367 continue
368 }
369
370 if inWhole {
371 if count == 3 {
372 b = append(b, sd.group[0])
373 count = 1
374 } else {
375 count++
376 }
377 }
378
379 b = append(b, s[i])
380 }
381
382 if num < 0 {
383
384 for j := len(symbol) - 1; j >= 0; j-- {
385 b = append(b, symbol[j])
386 }
387
388 for j := len(sd.currencyNegativePrefix) - 1; j >= 0; j-- {
389 b = append(b, sd.currencyNegativePrefix[j])
390 }
391
392 b = append(b, sd.minus[0])
393
394 } else {
395
396 for j := len(symbol) - 1; j >= 0; j-- {
397 b = append(b, symbol[j])
398 }
399
400 for j := len(sd.currencyPositivePrefix) - 1; j >= 0; j-- {
401 b = append(b, sd.currencyPositivePrefix[j])
402 }
403
404 }
405
406
407 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
408 b[i], b[j] = b[j], b[i]
409 }
410
411 if int(v) < 2 {
412
413 if v == 0 {
414 b = append(b, sd.decimal...)
415 }
416
417 for i := 0; i < 2-int(v); i++ {
418 b = append(b, '0')
419 }
420 }
421
422 return string(b)
423 }
424
425
426 func (sd *sd) FmtDateShort(t time.Time) string {
427
428 b := make([]byte, 0, 32)
429
430 if t.Year() > 0 {
431 b = strconv.AppendInt(b, int64(t.Year()), 10)
432 } else {
433 b = strconv.AppendInt(b, int64(-t.Year()), 10)
434 }
435
436 b = append(b, []byte{0x2d}...)
437
438 if t.Month() < 10 {
439 b = append(b, '0')
440 }
441
442 b = strconv.AppendInt(b, int64(t.Month()), 10)
443
444 b = append(b, []byte{0x2d}...)
445
446 if t.Day() < 10 {
447 b = append(b, '0')
448 }
449
450 b = strconv.AppendInt(b, int64(t.Day()), 10)
451
452 return string(b)
453 }
454
455
456 func (sd *sd) FmtDateMedium(t time.Time) string {
457
458 b := make([]byte, 0, 32)
459
460 if t.Year() > 0 {
461 b = strconv.AppendInt(b, int64(t.Year()), 10)
462 } else {
463 b = strconv.AppendInt(b, int64(-t.Year()), 10)
464 }
465
466 b = append(b, []byte{0x20}...)
467 b = append(b, sd.monthsAbbreviated[t.Month()]...)
468 b = append(b, []byte{0x20}...)
469 b = strconv.AppendInt(b, int64(t.Day()), 10)
470
471 return string(b)
472 }
473
474
475 func (sd *sd) FmtDateLong(t time.Time) string {
476
477 b := make([]byte, 0, 32)
478
479 if t.Year() > 0 {
480 b = strconv.AppendInt(b, int64(t.Year()), 10)
481 } else {
482 b = strconv.AppendInt(b, int64(-t.Year()), 10)
483 }
484
485 b = append(b, []byte{0x20}...)
486 b = append(b, sd.monthsWide[t.Month()]...)
487 b = append(b, []byte{0x20}...)
488 b = strconv.AppendInt(b, int64(t.Day()), 10)
489
490 return string(b)
491 }
492
493
494 func (sd *sd) FmtDateFull(t time.Time) string {
495
496 b := make([]byte, 0, 32)
497
498 if t.Year() > 0 {
499 b = strconv.AppendInt(b, int64(t.Year()), 10)
500 } else {
501 b = strconv.AppendInt(b, int64(-t.Year()), 10)
502 }
503
504 b = append(b, []byte{0x20}...)
505 b = append(b, sd.monthsWide[t.Month()]...)
506 b = append(b, []byte{0x20}...)
507 b = strconv.AppendInt(b, int64(t.Day()), 10)
508 b = append(b, []byte{0x2c, 0x20}...)
509 b = append(b, sd.daysWide[t.Weekday()]...)
510
511 return string(b)
512 }
513
514
515 func (sd *sd) FmtTimeShort(t time.Time) string {
516
517 b := make([]byte, 0, 32)
518
519 h := t.Hour()
520
521 if h > 12 {
522 h -= 12
523 }
524
525 b = strconv.AppendInt(b, int64(h), 10)
526 b = append(b, sd.timeSeparator...)
527
528 if t.Minute() < 10 {
529 b = append(b, '0')
530 }
531
532 b = strconv.AppendInt(b, int64(t.Minute()), 10)
533 b = append(b, []byte{0x20}...)
534
535 if t.Hour() < 12 {
536 b = append(b, sd.periodsAbbreviated[0]...)
537 } else {
538 b = append(b, sd.periodsAbbreviated[1]...)
539 }
540
541 return string(b)
542 }
543
544
545 func (sd *sd) FmtTimeMedium(t time.Time) string {
546
547 b := make([]byte, 0, 32)
548
549 h := t.Hour()
550
551 if h > 12 {
552 h -= 12
553 }
554
555 b = strconv.AppendInt(b, int64(h), 10)
556 b = append(b, sd.timeSeparator...)
557
558 if t.Minute() < 10 {
559 b = append(b, '0')
560 }
561
562 b = strconv.AppendInt(b, int64(t.Minute()), 10)
563 b = append(b, sd.timeSeparator...)
564
565 if t.Second() < 10 {
566 b = append(b, '0')
567 }
568
569 b = strconv.AppendInt(b, int64(t.Second()), 10)
570 b = append(b, []byte{0x20}...)
571
572 if t.Hour() < 12 {
573 b = append(b, sd.periodsAbbreviated[0]...)
574 } else {
575 b = append(b, sd.periodsAbbreviated[1]...)
576 }
577
578 return string(b)
579 }
580
581
582 func (sd *sd) FmtTimeLong(t time.Time) string {
583
584 b := make([]byte, 0, 32)
585
586 h := t.Hour()
587
588 if h > 12 {
589 h -= 12
590 }
591
592 b = strconv.AppendInt(b, int64(h), 10)
593 b = append(b, sd.timeSeparator...)
594
595 if t.Minute() < 10 {
596 b = append(b, '0')
597 }
598
599 b = strconv.AppendInt(b, int64(t.Minute()), 10)
600 b = append(b, sd.timeSeparator...)
601
602 if t.Second() < 10 {
603 b = append(b, '0')
604 }
605
606 b = strconv.AppendInt(b, int64(t.Second()), 10)
607 b = append(b, []byte{0x20}...)
608
609 if t.Hour() < 12 {
610 b = append(b, sd.periodsAbbreviated[0]...)
611 } else {
612 b = append(b, sd.periodsAbbreviated[1]...)
613 }
614
615 b = append(b, []byte{0x20}...)
616
617 tz, _ := t.Zone()
618 b = append(b, tz...)
619
620 return string(b)
621 }
622
623
624 func (sd *sd) FmtTimeFull(t time.Time) string {
625
626 b := make([]byte, 0, 32)
627
628 h := t.Hour()
629
630 if h > 12 {
631 h -= 12
632 }
633
634 b = strconv.AppendInt(b, int64(h), 10)
635 b = append(b, sd.timeSeparator...)
636
637 if t.Minute() < 10 {
638 b = append(b, '0')
639 }
640
641 b = strconv.AppendInt(b, int64(t.Minute()), 10)
642 b = append(b, sd.timeSeparator...)
643
644 if t.Second() < 10 {
645 b = append(b, '0')
646 }
647
648 b = strconv.AppendInt(b, int64(t.Second()), 10)
649 b = append(b, []byte{0x20}...)
650
651 if t.Hour() < 12 {
652 b = append(b, sd.periodsAbbreviated[0]...)
653 } else {
654 b = append(b, sd.periodsAbbreviated[1]...)
655 }
656
657 b = append(b, []byte{0x20}...)
658
659 tz, _ := t.Zone()
660
661 if btz, ok := sd.timezones[tz]; ok {
662 b = append(b, btz...)
663 } else {
664 b = append(b, tz...)
665 }
666
667 return string(b)
668 }
669
View as plain text