1 package km
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 km 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 &km{
47 locale: "km",
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", "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", "៛", "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", "Db", "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"},
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{"AM", "PM"},
69 periodsNarrow: []string{"a", "p"},
70 periodsWide: []string{"AM", "PM"},
71 erasAbbreviated: []string{"មុន គ.ស.", "គ.ស."},
72 erasNarrow: []string{"", ""},
73 erasWide: []string{"មុន\u200bគ្រិស្តសករាជ", "គ្រិស្តសករាជ"},
74 timezones: map[string]string{"ACDT": "ម៉ោង\u200bពេលថ្ងៃ\u200b\u200b\u200b\u200bនៅ\u200bអូស្ត្រាលី\u200bកណ្ដាល", "ACST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bអូស្ត្រាលី\u200bកណ្ដាល", "ACWDT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200b\u200bភាគ\u200bខាង\u200bលិច\u200bនៃ\u200bអូស្ត្រាលី\u200bកណ្ដាល", "ACWST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bភាគ\u200bខាង\u200bលិច\u200bនៃ\u200bអូស្ត្រាលី\u200bកណ្ដាល", "ADT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bអាត្លង់ទិក", "AEDT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bអូស្ត្រាលី\u200bខាង\u200bកើត", "AEST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bអូស្ត្រាលី\u200bខាង\u200bកើត", "AKDT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200b\u200bអាឡាស្កា", "AKST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bអាឡាស្កា", "ARST": "ម៉ោង\u200bនៅ\u200bអាហ្សង់ទីននារដូវក្តៅ", "ART": "ម៉ោងស្តង់ដារ\u200bនៅ\u200bអាហ្សង់ទីន", "AST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bអាត្លង់ទិក", "AWDT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bអូស្ត្រាលី\u200bខាង\u200bលិច", "AWST": "ម៉ោង\u200b\u200bស្តង់ដារ\u200bនៅ\u200bអូស្ត្រាលី\u200bខាង\u200bលិច", "BOT": "ម៉ោង\u200bនៅ\u200bបូលីវី", "BT": "ម៉ោងនៅប៊ូតង់", "CAT": "ម៉ោង\u200bនៅ\u200bអាហ្វ្រិក\u200bកណ្ដាល", "CDT": "ម៉ោង\u200b\u200bពេលថ្ងៃនៅ\u200bទ្វីបអាមេរិក\u200bខាង\u200bជើងភាគកណ្តាល", "CHADT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bចាថាំ", "CHAST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bចាថាំ", "CLST": "ម៉ោងនៅស៊ីលីនារដូវក្តៅ", "CLT": "ម៉ោងស្តង់ដារនៅស៊ីលី", "COST": "ម៉ោង\u200bនៅ\u200bកូឡុំប៊ីនា\u200bរដូវ\u200bក្ដៅ", "COT": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bកូឡុំប៊ី", "CST": "ម៉ោង\u200b\u200bស្តង់ដារនៅ\u200bទ្វីបអាមេរិក\u200bខាង\u200bជើងភាគកណ្តាល", "ChST": "ម៉ោង\u200bស្តង់ដារនៅ\u200bចាំម៉ូរ៉ូ", "EAT": "ម៉ោង\u200bនៅ\u200bអាហ្វ្រិក\u200bខាង\u200bកើត", "ECT": "ម៉ោង\u200bនៅ\u200bអេក្វាទ័រ", "EDT": "ម៉ោងពេលថ្ងៃនៅទ្វីបអាមេរិកខាងជើងភាគខាងកើត", "EST": "ម៉ោងស្តង់ដារនៅទ្វីបអាមេរិកខាងជើងភាគខាងកើត", "GFT": "ម៉ោង\u200bនៅ\u200bហ្គីយ៉ាន\u200bបារាំង", "GMT": "ម៉ោងនៅគ្រីនវិច", "GST": "ម៉ោង\u200bស្តង់ដា\u200bនៅ\u200bកាល់", "GYT": "ម៉ោង\u200bនៅ\u200bហ្គីយ៉ាន", "HADT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bហាវៃ-អាល់ដ្យូសិន", "HAST": "ម៉ោង\u200bស្តង់ដារ\u200b\u200bនៅ\u200bហាវៃ-អាល់ដ្យូសិន", "HAT": "ម៉ោង\u200bពេលថ្ងៃ\u200bនៅ\u200bញូវហ្វោនឡែន", "HECU": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bគុយបា", "HEEG": "ម៉ោង\u200bនៅ\u200bហ្គ្រីនលែនខាង\u200bកើតនា\u200bរដូវ\u200bក្ដៅ", "HENOMX": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bម៉ិកស៊ិកភាគពាយព្យ", "HEOG": "ម៉ោងនៅហ្គ្រីនលែនខាងលិចនារដូវក្តៅ", "HEPM": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅសង់\u200bព្យែរ និង\u200bមីគុយឡុង", "HEPMX": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bប៉ាស៊ីហ្វិក\u200bម៉ិកស៊ិក", "HKST": "ម៉ោងនៅ\u200bហុងកុងនា\u200bរដូវ\u200bក្ដៅ\u200b", "HKT": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bហុងកុង", "HNCU": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bគុយបា", "HNEG": "ម៉ោង\u200b\u200b\u200bស្តង់ដារ\u200bនៅ\u200b\u200bហ្គ្រីនលែន\u200bខាង\u200bកើត", "HNNOMX": "ម៉ោង\u200bស្តង់ដារនៅ\u200bម៉ិកស៊ិកភាគពាយព្យ", "HNOG": "ម៉ោងស្តង់ដារនៅហ្គ្រីនលែនខាងលិច", "HNPM": "ម៉ោង\u200bស្តង់ដារ\u200bនៅសង់\u200bព្យែរ និង\u200bមីគុយឡុង", "HNPMX": "ម៉ោង\u200bស្តង់ដា\u200bនៅ\u200bប៉ាស៊ីហ្វិក\u200bម៉ិកស៊ិក", "HNT": "ម៉ោង\u200b\u200bស្តង់ដារ\u200b\u200bនៅ\u200bញូវហ្វោនឡែន", "IST": "ម៉ោង\u200bស្តង់ដារនៅ\u200bឥណ្ឌា", "JDT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅជប៉ុន", "JST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bជប៉ុន", "LHDT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bឡតហៅ", "LHST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bឡត\u200bហៅ", "MDT": "MDT", "MESZ": "ម៉ោង\u200bនៅ\u200bអឺរ៉ុប\u200bកណ្ដាលនា\u200bរដូវ\u200bក្ដៅ", "MEZ": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bអឺរ៉ុប\u200bកណ្ដាល", "MST": "MST", "MYT": "ម៉ោង\u200bនៅ\u200bម៉ាឡេស៊ី", "NZDT": "ម៉ោង\u200bពេល\u200bថ្ងៃ\u200bនៅ\u200bនូវែលសេឡង់", "NZST": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bនូវែលសេឡង់", "OESZ": "ម៉ោង\u200bនៅ\u200bអឺរ៉ុប\u200b\u200bខាង\u200bកើត\u200bនា\u200bរដូវ\u200bក្ដៅ", "OEZ": "ម៉ោង\u200bស្តង់ដារ\u200b\u200bនៅ\u200bអឺរ៉ុប\u200b\u200bខាង\u200bកើត\u200b", "PDT": "ម៉ោង\u200b\u200bពេលថ្ងៃនៅទ្វីប\u200bអាមរិក\u200bខាង\u200bជើងភាគខាងលិច", "PST": "ម៉ោងស្តង់ដារ\u200b\u200b\u200bនៅទ្វីប\u200bអាមរិក\u200bខាង\u200bជើងភាគខាងលិច", "SAST": "ម៉ោង\u200bនៅ\u200bអាហ្វ្រិក\u200bខាង\u200bត្បូង", "SGT": "ម៉ោង\u200bនៅ\u200bសិង្ហបូរី", "SRT": "ម៉ោង\u200bនៅ\u200bសូរីណាម", "TMST": "ម៉ោង\u200bរដូវ\u200bក្ដៅ\u200bនៅ\u200bតួកម៉េនីស្ថាន\u200b", "TMT": "ម៉ោង\u200bស្តង់ដារ\u200bនៅតួកម៉េនីស្ថាន", "UYST": "ម៉ោង\u200bនៅ\u200bអ៊ុយរូហ្គាយនា\u200b\u200bរដូវ\u200bក្ដៅ", "UYT": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bអ៊ុយរូហ្គាយ", "VET": "ម៉ោង\u200bនៅ\u200bវ៉េណេស៊ុយអេឡា", "WARST": "ម៉ោង\u200bនៅ\u200bអាហ្សង់ទីនភាគខាងលិចនារដូវក្តៅ", "WART": "ម៉ោងស្តង់ដារ\u200bនៅ\u200bអាហ្សង់ទីនភាគខាងលិច", "WAST": "ម៉ោងនៅ\u200bអាហ្វ្រិក\u200b\u200b\u200bខាងលិច\u200b\u200bនារដូវ\u200bក្ដៅ\u200b", "WAT": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bអាហ្វ្រិក\u200bខាង\u200bលិច", "WESZ": "ម៉ោង\u200bនៅ\u200bអឺរ៉ុប\u200bខាង\u200bលិចនារដូវ\u200bក្ដៅ\u200b", "WEZ": "ម៉ោង\u200bស្តង់ដារ\u200bនៅ\u200bអឺរ៉ុប\u200bខាង\u200bលិច", "WIB": "ម៉ោង\u200bនៅ\u200bឥណ្ឌូណេស៊ី\u200b\u200bខាង\u200bលិច", "WIT": "ម៉ោង\u200bនៅ\u200bឥណ្ឌូណេស៊ី\u200b\u200bខាង\u200bកើត", "WITA": "ម៉ោង\u200bនៅ\u200bឥណ្ឌូណេស៊ី\u200b\u200b\u200bកណ្ដាល", "∅∅∅": "ម៉ោង\u200b\u200bនៅ\u200bប៉េរូនារដូវ\u200bក្ដៅ"},
75 }
76 }
77
78
79 func (km *km) Locale() string {
80 return km.locale
81 }
82
83
84 func (km *km) PluralsCardinal() []locales.PluralRule {
85 return km.pluralsCardinal
86 }
87
88
89 func (km *km) PluralsOrdinal() []locales.PluralRule {
90 return km.pluralsOrdinal
91 }
92
93
94 func (km *km) PluralsRange() []locales.PluralRule {
95 return km.pluralsRange
96 }
97
98
99 func (km *km) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
100 return locales.PluralRuleOther
101 }
102
103
104 func (km *km) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
105 return locales.PluralRuleOther
106 }
107
108
109 func (km *km) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
110 return locales.PluralRuleOther
111 }
112
113
114 func (km *km) MonthAbbreviated(month time.Month) string {
115 return km.monthsAbbreviated[month]
116 }
117
118
119 func (km *km) MonthsAbbreviated() []string {
120 return km.monthsAbbreviated[1:]
121 }
122
123
124 func (km *km) MonthNarrow(month time.Month) string {
125 return km.monthsNarrow[month]
126 }
127
128
129 func (km *km) MonthsNarrow() []string {
130 return km.monthsNarrow[1:]
131 }
132
133
134 func (km *km) MonthWide(month time.Month) string {
135 return km.monthsWide[month]
136 }
137
138
139 func (km *km) MonthsWide() []string {
140 return km.monthsWide[1:]
141 }
142
143
144 func (km *km) WeekdayAbbreviated(weekday time.Weekday) string {
145 return km.daysAbbreviated[weekday]
146 }
147
148
149 func (km *km) WeekdaysAbbreviated() []string {
150 return km.daysAbbreviated
151 }
152
153
154 func (km *km) WeekdayNarrow(weekday time.Weekday) string {
155 return km.daysNarrow[weekday]
156 }
157
158
159 func (km *km) WeekdaysNarrow() []string {
160 return km.daysNarrow
161 }
162
163
164 func (km *km) WeekdayShort(weekday time.Weekday) string {
165 return km.daysShort[weekday]
166 }
167
168
169 func (km *km) WeekdaysShort() []string {
170 return km.daysShort
171 }
172
173
174 func (km *km) WeekdayWide(weekday time.Weekday) string {
175 return km.daysWide[weekday]
176 }
177
178
179 func (km *km) WeekdaysWide() []string {
180 return km.daysWide
181 }
182
183
184 func (km *km) Decimal() string {
185 return km.decimal
186 }
187
188
189 func (km *km) Group() string {
190 return km.group
191 }
192
193
194 func (km *km) Minus() string {
195 return km.minus
196 }
197
198
199 func (km *km) 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, km.decimal[0])
211 inWhole = true
212 continue
213 }
214
215 if inWhole {
216 if count == 3 {
217 b = append(b, km.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, km.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 (km *km) 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, km.decimal[0])
250 continue
251 }
252
253 b = append(b, s[i])
254 }
255
256 if num < 0 {
257 b = append(b, km.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, km.percent...)
266
267 return string(b)
268 }
269
270
271 func (km *km) FmtCurrency(num float64, v uint64, currency currency.Type) string {
272
273 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
274 symbol := km.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, km.decimal[0])
284 inWhole = true
285 continue
286 }
287
288 if inWhole {
289 if count == 3 {
290 b = append(b, km.group[0])
291 count = 1
292 } else {
293 count++
294 }
295 }
296
297 b = append(b, s[i])
298 }
299
300 if num < 0 {
301 b = append(b, km.minus[0])
302 }
303
304
305 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
306 b[i], b[j] = b[j], b[i]
307 }
308
309 if int(v) < 2 {
310
311 if v == 0 {
312 b = append(b, km.decimal...)
313 }
314
315 for i := 0; i < 2-int(v); i++ {
316 b = append(b, '0')
317 }
318 }
319
320 b = append(b, symbol...)
321
322 return string(b)
323 }
324
325
326
327 func (km *km) FmtAccounting(num float64, v uint64, currency currency.Type) string {
328
329 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
330 symbol := km.currencies[currency]
331 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
332 count := 0
333 inWhole := v == 0
334 b := make([]byte, 0, l)
335
336 for i := len(s) - 1; i >= 0; i-- {
337
338 if s[i] == '.' {
339 b = append(b, km.decimal[0])
340 inWhole = true
341 continue
342 }
343
344 if inWhole {
345 if count == 3 {
346 b = append(b, km.group[0])
347 count = 1
348 } else {
349 count++
350 }
351 }
352
353 b = append(b, s[i])
354 }
355
356 if num < 0 {
357
358 b = append(b, km.currencyNegativePrefix[0])
359
360 }
361
362
363 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
364 b[i], b[j] = b[j], b[i]
365 }
366
367 if int(v) < 2 {
368
369 if v == 0 {
370 b = append(b, km.decimal...)
371 }
372
373 for i := 0; i < 2-int(v); i++ {
374 b = append(b, '0')
375 }
376 }
377
378 if num < 0 {
379 b = append(b, km.currencyNegativeSuffix...)
380 b = append(b, symbol...)
381 } else {
382
383 b = append(b, symbol...)
384 }
385
386 return string(b)
387 }
388
389
390 func (km *km) FmtDateShort(t time.Time) string {
391
392 b := make([]byte, 0, 32)
393
394 b = strconv.AppendInt(b, int64(t.Day()), 10)
395 b = append(b, []byte{0x2f}...)
396 b = strconv.AppendInt(b, int64(t.Month()), 10)
397 b = append(b, []byte{0x2f}...)
398
399 if t.Year() > 9 {
400 b = append(b, strconv.Itoa(t.Year())[2:]...)
401 } else {
402 b = append(b, strconv.Itoa(t.Year())[1:]...)
403 }
404
405 return string(b)
406 }
407
408
409 func (km *km) FmtDateMedium(t time.Time) string {
410
411 b := make([]byte, 0, 32)
412
413 b = strconv.AppendInt(b, int64(t.Day()), 10)
414 b = append(b, []byte{0x20}...)
415 b = append(b, km.monthsAbbreviated[t.Month()]...)
416 b = append(b, []byte{0x20}...)
417
418 if t.Year() > 0 {
419 b = strconv.AppendInt(b, int64(t.Year()), 10)
420 } else {
421 b = strconv.AppendInt(b, int64(-t.Year()), 10)
422 }
423
424 return string(b)
425 }
426
427
428 func (km *km) FmtDateLong(t time.Time) string {
429
430 b := make([]byte, 0, 32)
431
432 b = strconv.AppendInt(b, int64(t.Day()), 10)
433 b = append(b, []byte{0x20}...)
434 b = append(b, km.monthsWide[t.Month()]...)
435 b = append(b, []byte{0x20}...)
436
437 if t.Year() > 0 {
438 b = strconv.AppendInt(b, int64(t.Year()), 10)
439 } else {
440 b = strconv.AppendInt(b, int64(-t.Year()), 10)
441 }
442
443 return string(b)
444 }
445
446
447 func (km *km) FmtDateFull(t time.Time) string {
448
449 b := make([]byte, 0, 32)
450
451 b = append(b, km.daysWide[t.Weekday()]...)
452 b = append(b, []byte{0x20}...)
453 b = strconv.AppendInt(b, int64(t.Day()), 10)
454 b = append(b, []byte{0x20}...)
455 b = append(b, km.monthsWide[t.Month()]...)
456 b = append(b, []byte{0x20}...)
457
458 if t.Year() > 0 {
459 b = strconv.AppendInt(b, int64(t.Year()), 10)
460 } else {
461 b = strconv.AppendInt(b, int64(-t.Year()), 10)
462 }
463
464 return string(b)
465 }
466
467
468 func (km *km) FmtTimeShort(t time.Time) string {
469
470 b := make([]byte, 0, 32)
471
472 h := t.Hour()
473
474 if h > 12 {
475 h -= 12
476 }
477
478 b = strconv.AppendInt(b, int64(h), 10)
479 b = append(b, km.timeSeparator...)
480
481 if t.Minute() < 10 {
482 b = append(b, '0')
483 }
484
485 b = strconv.AppendInt(b, int64(t.Minute()), 10)
486 b = append(b, []byte{0x20}...)
487
488 if t.Hour() < 12 {
489 b = append(b, km.periodsAbbreviated[0]...)
490 } else {
491 b = append(b, km.periodsAbbreviated[1]...)
492 }
493
494 return string(b)
495 }
496
497
498 func (km *km) FmtTimeMedium(t time.Time) string {
499
500 b := make([]byte, 0, 32)
501
502 h := t.Hour()
503
504 if h > 12 {
505 h -= 12
506 }
507
508 b = strconv.AppendInt(b, int64(h), 10)
509 b = append(b, km.timeSeparator...)
510
511 if t.Minute() < 10 {
512 b = append(b, '0')
513 }
514
515 b = strconv.AppendInt(b, int64(t.Minute()), 10)
516 b = append(b, km.timeSeparator...)
517
518 if t.Second() < 10 {
519 b = append(b, '0')
520 }
521
522 b = strconv.AppendInt(b, int64(t.Second()), 10)
523 b = append(b, []byte{0x20}...)
524
525 if t.Hour() < 12 {
526 b = append(b, km.periodsAbbreviated[0]...)
527 } else {
528 b = append(b, km.periodsAbbreviated[1]...)
529 }
530
531 return string(b)
532 }
533
534
535 func (km *km) FmtTimeLong(t time.Time) string {
536
537 b := make([]byte, 0, 32)
538
539 h := t.Hour()
540
541 if h > 12 {
542 h -= 12
543 }
544
545 b = strconv.AppendInt(b, int64(h), 10)
546 b = append(b, km.timeSeparator...)
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, km.timeSeparator...)
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}...)
561
562 if t.Hour() < 12 {
563 b = append(b, km.periodsAbbreviated[0]...)
564 } else {
565 b = append(b, km.periodsAbbreviated[1]...)
566 }
567
568 b = append(b, []byte{0x20}...)
569
570 tz, _ := t.Zone()
571 b = append(b, tz...)
572
573 return string(b)
574 }
575
576
577 func (km *km) FmtTimeFull(t time.Time) string {
578
579 b := make([]byte, 0, 32)
580
581 h := t.Hour()
582
583 if h > 12 {
584 h -= 12
585 }
586
587 b = strconv.AppendInt(b, int64(h), 10)
588 b = append(b, km.timeSeparator...)
589
590 if t.Minute() < 10 {
591 b = append(b, '0')
592 }
593
594 b = strconv.AppendInt(b, int64(t.Minute()), 10)
595 b = append(b, km.timeSeparator...)
596
597 if t.Second() < 10 {
598 b = append(b, '0')
599 }
600
601 b = strconv.AppendInt(b, int64(t.Second()), 10)
602 b = append(b, []byte{0x20}...)
603
604 if t.Hour() < 12 {
605 b = append(b, km.periodsAbbreviated[0]...)
606 } else {
607 b = append(b, km.periodsAbbreviated[1]...)
608 }
609
610 b = append(b, []byte{0x20}...)
611
612 tz, _ := t.Zone()
613
614 if btz, ok := km.timezones[tz]; ok {
615 b = append(b, btz...)
616 } else {
617 b = append(b, tz...)
618 }
619
620 return string(b)
621 }
622
View as plain text