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