@@ -20,14 +20,10 @@ import (
20
20
"github.com/xuri/nfp"
21
21
)
22
22
23
- // supportedTokenTypes list the supported number format token types currently.
24
- var supportedTokenTypes = []string {
25
- nfp .TokenTypeCurrencyLanguage ,
26
- nfp .TokenTypeDateTimes ,
27
- nfp .TokenTypeElapsedDateTimes ,
28
- nfp .TokenTypeGeneral ,
29
- nfp .TokenTypeLiteral ,
30
- nfp .TokenSubTypeLanguageInfo ,
23
+ type languageInfo struct {
24
+ apFmt string
25
+ tags []string
26
+ localMonth func (t time.Time , abbr int ) string
31
27
}
32
28
33
29
// numberFormat directly maps the number format parser runtime required
@@ -41,6 +37,137 @@ type numberFormat struct {
41
37
ap , afterPoint , beforePoint , localCode , result , value , valueSectionType string
42
38
}
43
39
40
+ // supportedTokenTypes list the supported number format token types currently.
41
+ var (
42
+ supportedTokenTypes = []string {
43
+ nfp .TokenTypeCurrencyLanguage ,
44
+ nfp .TokenTypeDateTimes ,
45
+ nfp .TokenTypeElapsedDateTimes ,
46
+ nfp .TokenTypeGeneral ,
47
+ nfp .TokenTypeLiteral ,
48
+ nfp .TokenSubTypeLanguageInfo ,
49
+ }
50
+ // supportedLanguageInfo directly maps the supported language ID and tags.
51
+ supportedLanguageInfo = map [string ]languageInfo {
52
+ "36" : {tags : []string {"af" }, localMonth : localMonthsNameAfrikaans , apFmt : apFmtAfrikaans },
53
+ "445" : {tags : []string {"bn-IN" }, localMonth : localMonthsNameBangla , apFmt : nfp .AmPm [0 ]},
54
+ "4" : {tags : []string {"zh-Hans" }, localMonth : localMonthsNameChinese1 , apFmt : nfp .AmPm [2 ]},
55
+ "7804" : {tags : []string {"zh" }, localMonth : localMonthsNameChinese1 , apFmt : nfp .AmPm [2 ]},
56
+ "804" : {tags : []string {"zh-CN" }, localMonth : localMonthsNameChinese1 , apFmt : nfp .AmPm [2 ]},
57
+ "1004" : {tags : []string {"zh-SG" }, localMonth : localMonthsNameChinese2 , apFmt : nfp .AmPm [2 ]},
58
+ "7C04" : {tags : []string {"zh-Hant" }, localMonth : localMonthsNameChinese3 , apFmt : nfp .AmPm [2 ]},
59
+ "C04" : {tags : []string {"zh-HK" }, localMonth : localMonthsNameChinese2 , apFmt : nfp .AmPm [2 ]},
60
+ "1404" : {tags : []string {"zh-MO" }, localMonth : localMonthsNameChinese3 , apFmt : nfp .AmPm [2 ]},
61
+ "404" : {tags : []string {"zh-TW" }, localMonth : localMonthsNameChinese3 , apFmt : nfp .AmPm [2 ]},
62
+ "9" : {tags : []string {"en" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
63
+ "1000" : {tags : []string {
64
+ "aa" , "aa-DJ" , "aa-ER" , "aa-ER" , "aa-NA" , "agq" , "agq-CM" , "ak" , "ak-GH" , "sq-ML" ,
65
+ "gsw-LI" , "gsw-CH" , "ar-TD" , "ar-KM" , "ar-DJ" , "ar-ER" , "ar-IL" , "ar-MR" , "ar-PS" ,
66
+ "ar-SO" , "ar-SS" , "ar-SD" , "ar-001" , "ast" , "ast-ES" , "asa" , "asa-TZ" , "ksf" , "ksf-CM" ,
67
+ "bm" , "bm-Latn-ML" , "bas" , "bas-CM" , "bem" , "bem-ZM" , "bez" , "bez-TZ" , "byn" , "byn-ER" ,
68
+ "brx" , "brx-IN" , "ca-AD" , "ca-FR" , "ca-IT" , "ceb" , "ceb-Latn" , "ceb-Latn-PH" , "tzm-Latn-MA" ,
69
+ "ccp" , "ccp-Cakm" , "ccp-Cakm-BD" , "ccp-Cakm-IN" , "ce-RU" , "cgg" , "cgg-UG" , "cu-RU" , "swc" ,
70
+ "swc-CD" , "kw" , "ke-GB" , "da-GL" , "dua" , "dua-CM" , "nl-AW" , "nl-BQ" , "nl-CW" , "nl-SX" ,
71
+ "nl-SR" , "dz" , "ebu" , "ebu-KE" , "en-AS" , "en-AI" , "en-AG" , "en-AT" , "en-BS" , "en-BB" ,
72
+ "en-BE" , "en-BM" , "en-BW" , "en-IO" , "en-VG" , "en-BI" , "en-CM" , "en-KY" , "en-CX" , "en-CC" ,
73
+ "en-CK" , "en-CY" , "en-DK" , "en-DM" , "en-ER" , "en-150" , "en-FK" , "en-FI" , "en-FJ" , "en-GM" ,
74
+ "en-DE" , "en-GH" , "en-GI" , "en-GD" , "en-GU" , "en-GG" , "en-GY" , "en-IM" , "en-IL" , "en-JE" ,
75
+ "en-KE" , "en-KI" , "en-LS" , "en-LR" , "en-MO" , "en-MG" , "en-MW" , "en-MT" , "en-MH" , "en-MU" ,
76
+ "en-FM" , "en-MS" , "en-NA" , "en-NR" , "en-NL" , "en-NG" , "en-NU" , "en-NF" , "en-MP" , "en-PK" ,
77
+ "en-PW" , "en-PG" , "en-PN" , "en-PR" , "en-RW" , "en-KN" , "en-LC" , "en-VC" , "en-WS" , "en-SC" ,
78
+ "en-SL" , "en-SX" , "en-SI" , "en-SB" , "en-SS" , "en-SH" , "en-SD" , "en-SZ" , "en-SE" , "en-CH" ,
79
+ "en-TZ" , "en-TK" , "en-TO" , "en-TC" , "en-TV" , "en-UG" , "en-UM" , "en-VI" , "en-VU" , "en-001" ,
80
+ "en-ZM" , "eo" , "eo-001" , "ee" , "ee-GH" , "ee-TG" , "ewo" , "ewo-CM" , "fo-DK" , "fr-DZ" ,
81
+ "fr-BJ" , "fr-BF" , "fr-BI" , "fr-CF" , "fr-TD" , "fr-KM" , "fr-CG" , "fr-DJ" , "fr-GQ" , "fr-GF" ,
82
+ "fr-PF" , "fr-GA" , "fr-GP" , "fr-GN" , "fr-MG" , "fr-MQ" , "fr-MR" , "fr-MU" , "fr-YT" , "fr-NC" ,
83
+ "fr-NE" , "fr-RW" , "fr-BL" , "fr-MF" , "fr-PM" , "fr-SC" , "fr-SY" , "fr-TG" , "fr-TN" , "fr-VU" ,
84
+ "fr-WF" , "fur" , "fur-IT" , "ff-Latn-BF" , "ff-CM" , "ff-Latn-CM" , "ff-Latn-GM" , "ff-Latn-GH" ,
85
+ "ff-GN" , "ff-Latn-GN" , "ff-Latn-GW" , "ff-Latn-LR" , "ff-MR" , "ff-Latn-MR" , "ff-Latn-NE" ,
86
+ "ff-Latn-SL" , "lg" , "lg-UG" , "de-BE" , "de-IT" , "el-CY" , "guz" , "guz-KE" , "ha-Latn-GH" ,
87
+ "ha-Latn-NG" , "ia-FR" , "ia-001" , "it-SM" , "it-VA" , "jv" , "jv-Latn" , "jv-Latn-ID" , "dyo" ,
88
+ "dyo-SN" , "kea" , "kea-CV" , "kab" , "kab-DZ" , "kkj" , "kkj-CM" , "kln" , "kln-KE" , "kam" ,
89
+ "kam-KE" , "ks-Arab-IN" , "ki" , "ki-KE" , "sw-TZ" , "sw-UG" , "ko-KP" , "khq" , "khq-ML" , "ses" ,
90
+ "ses-ML" , "nmg" , "nmq-CM" , "ku-Arab-IR" , "lkt" , "lkt-US" , "lag" , "lag-TZ" , "ln" , "ln-AO" ,
91
+ "ln-CF" , "ln-CD" , "nds" , "nds-DE" , "nds-NL" , "lu" , "lu-CD" , "luo" , "luo" , "luo-KE" , "luy" ,
92
+ "luy-KE" , "jmc" , "jmc-TZ" , "mgh" , "mgh-MZ" , "kde" , "kde-TZ" , "mg" , "mg-MG" , "gv" , "gv-IM" ,
93
+ "mas" , "mas-KE" , "mas-TZ" , "mas-IR" , "mer" , "mer-KE" , "mgo" , "mgo-CM" , "mfe" , "mfe-MU" ,
94
+ "mua" , "mua-CM" , "nqo" , "nqo-GN" , "nqa" , "naq-NA" , "nnh" , "nnh-CM" , "jgo" , "jgo-CM" ,
95
+ "lrc-IQ" , "lrc-IR" , "nd" , "nd-ZW" , "nb-SJ" , "nus" , "nus-SD" , "nus-SS" , "nyn" , "nyn-UG" ,
96
+ "om-KE" , "os" , "os-GE" , "os-RU" , "ps-PK" , "fa-AF" , "pt-AO" , "pt-CV" , "pt-GQ" , "pt-GW" ,
97
+ "pt-LU" , "pt-MO" , "pt-MZ" , "pt-ST" , "pt-CH" , "pt-TL" , "prg-001" , "ksh" , "ksh-DE" , "rof" ,
98
+ "rof-TZ" , "rn" , "rn-BI" , "ru-BY" , "ru-KZ" , "ru-KG" , "ru-UA" , "rwk" , "rwk-TZ" , "ssy" ,
99
+ "ssy-ER" , "saq" , "saq-KE" , "sg" , "sq-CF" , "sbp" , "sbp-TZ" , "seh" , "seh-MZ" , "ksb" , "ksb-TZ" ,
100
+ "sn" , "sn-Latn" , "sn-Latn-ZW" , "xog" , "xog-UG" , "so-DJ" , "so-ET" , "so-KE" , "nr" , "nr-ZA" ,
101
+ "st-LS" , "es-BZ" , "es-BR" , "es-PH" , "zgh" , "zgh-Tfng-MA" , "zgh-Tfng" , "ss" , "ss-ZA" ,
102
+ "ss-SZ" , "sv-AX" , "shi" , "shi-Tfng" , "shi-Tfng-MA" , "shi-Latn" , "shi-Latn-MA" , "dav" ,
103
+ "dav-KE" , "ta-MY" , "ta-SG" , "twq" , "twq-NE" , "teo" , "teo-KE" , "teo-UG" , "bo-IN" , "tig" ,
104
+ "tig-ER" , "to" , "to-TO" , "tr-CY" , "uz-Arab" , "us-Arab-AF" , "vai" , "vai-Vaii" ,
105
+ "vai-Vaii-LR" , "vai-Latn-LR" , "vai-Latn" , "vo" , "vo-001" , "vun" , "vun-TZ" , "wae" ,
106
+ "wae-CH" , "wal" , "wae-ET" , "yav" , "yav-CM" , "yo-BJ" , "dje" , "dje-NE" ,
107
+ }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
108
+ "C09" : {tags : []string {"en-AU" }, localMonth : localMonthsNameEnglish , apFmt : strings .ToLower (nfp .AmPm [0 ])},
109
+ "2829" : {tags : []string {"en-BZ" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
110
+ "1009" : {tags : []string {"en-CA" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
111
+ "2409" : {tags : []string {"en-029" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
112
+ "3C09" : {tags : []string {"en-HK" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
113
+ "4009" : {tags : []string {"en-IN" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
114
+ "1809" : {tags : []string {"en-IE" }, localMonth : localMonthsNameEnglish , apFmt : strings .ToLower (nfp .AmPm [0 ])},
115
+ "2009" : {tags : []string {"en-JM" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
116
+ "4409" : {tags : []string {"en-MY" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
117
+ "1409" : {tags : []string {"en-NZ" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
118
+ "3409" : {tags : []string {"en-PH" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
119
+ "4809" : {tags : []string {"en-SG" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
120
+ "1C09" : {tags : []string {"en-ZA" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
121
+ "2C09" : {tags : []string {"en-TT" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
122
+ "4C09" : {tags : []string {"en-AE" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
123
+ "809" : {tags : []string {"en-GB" }, localMonth : localMonthsNameEnglish , apFmt : strings .ToLower (nfp .AmPm [0 ])},
124
+ "409" : {tags : []string {"en-US" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
125
+ "3009" : {tags : []string {"en-ZW" }, localMonth : localMonthsNameEnglish , apFmt : nfp .AmPm [0 ]},
126
+ "C" : {tags : []string {"fr" }, localMonth : localMonthsNameFrench , apFmt : nfp .AmPm [0 ]},
127
+ "7" : {tags : []string {"de" }, localMonth : localMonthsNameGerman , apFmt : nfp .AmPm [0 ]},
128
+ "C07" : {tags : []string {"de-AT" }, localMonth : localMonthsNameAustria , apFmt : nfp .AmPm [0 ]},
129
+ "407" : {tags : []string {"de-DE" }, localMonth : localMonthsNameGerman , apFmt : nfp .AmPm [0 ]},
130
+ "10" : {tags : []string {"it" }, localMonth : localMonthsNameItalian , apFmt : nfp .AmPm [0 ]},
131
+ "11" : {tags : []string {"ja" }, localMonth : localMonthsNameChinese3 , apFmt : apFmtJapanese },
132
+ "411" : {tags : []string {"ja-JP" }, localMonth : localMonthsNameChinese3 , apFmt : apFmtJapanese },
133
+ "12" : {tags : []string {"ko" }, localMonth : localMonthsNameKorean , apFmt : apFmtKorean },
134
+ "412" : {tags : []string {"ko-KR" }, localMonth : localMonthsNameKorean , apFmt : apFmtKorean },
135
+ }
136
+ // monthNamesBangla list the month names in the Bangla.
137
+ monthNamesBangla = []string {
138
+ "\u099C \u09BE \u09A8 \u09C1 \u09AF \u09BC \u09BE \u09B0 \u09C0 " ,
139
+ "\u09AB \u09C7 \u09AC \u09CD \u09B0 \u09C1 \u09AF \u09BC \u09BE \u09B0 \u09C0 " ,
140
+ "\u09AE \u09BE \u09B0 \u09CD \u099A " ,
141
+ "\u098F \u09AA \u09CD \u09B0 \u09BF \u09B2 " ,
142
+ "\u09AE \u09C7 " ,
143
+ "\u099C \u09C1 \u09A8 " ,
144
+ "\u099C \u09C1 \u09B2 \u09BE \u0987 " ,
145
+ "\u0986 \u0997 \u09B8 \u09CD \u099F " ,
146
+ "\u09B8 \u09C7 \u09AA \u09CD \u099F \u09C7 \u09AE \u09CD \u09AC \u09B0 " ,
147
+ "\u0985 \u0995 \u09CD \u099F \u09CB \u09AC \u09B0 " ,
148
+ "\u09A8 \u09AD \u09C7 \u09AE \u09CD \u09AC \u09B0 " ,
149
+ "\u09A1 \u09BF \u09B8 \u09C7 \u09AE \u09CD \u09AC \u09B0 " ,
150
+ }
151
+ // monthNamesAfrikaans list the month names in the Afrikaans.
152
+ monthNamesAfrikaans = []string {"Januarie" , "Februarie" , "Maart" , "April" , "Mei" , "Junie" , "Julie" , "Augustus" , "September" , "Oktober" , "November" , "Desember" }
153
+ // monthNamesChinese list the month names in the Chinese.
154
+ monthNamesChinese = []string {"一" , "二" , "三" , "四" , "五" , "六" , "七" , "八" , "九" , "十" , "十一" , "十二" }
155
+ // monthNamesFrench list the month names in the French.
156
+ monthNamesFrench = []string {"janvier" , "février" , "mars" , "avril" , "mai" , "juin" , "juillet" , "août" , "septembre" , "octobre" , "novembre" , "décembre" }
157
+ // monthNamesGerman list the month names in the German.
158
+ monthNamesGerman = []string {"Januar" , "Februar" , "März" , "April" , "Mai" , "Juni" , "Juli" , "August" , "September" , "Oktober" , "November" , "Dezember" }
159
+ // monthNamesAustria list the month names in the Austria.
160
+ monthNamesAustria = []string {"Jänner" , "Februar" , "März" , "April" , "Mai" , "Juni" , "Juli" , "August" , "September" , "Oktober" , "November" , "Dezember" }
161
+ // monthNamesItalian list the month names in the Italian.
162
+ monthNamesItalian = []string {"gennaio" , "febbraio" , "marzo" , "aprile" , "maggio" , "giugno" , "luglio" , "agosto" , "settembre" , "ottobre" , "novembre" , "dicembre" }
163
+ // apFmtAfrikaans defined the AM/PM name in the Afrikaans.
164
+ apFmtAfrikaans = "vm./nm."
165
+ // apFmtJapanese defined the AM/PM name in the Japanese.
166
+ apFmtJapanese = "午前/午後"
167
+ // apFmtJapanese defined the AM/PM name in the Korean.
168
+ apFmtKorean = "오전/오후"
169
+ )
170
+
44
171
// prepareNumberic split the number into two before and after parts by a
45
172
// decimal point.
46
173
func (nf * numberFormat ) prepareNumberic (value string ) {
@@ -116,21 +243,155 @@ func (nf *numberFormat) currencyLanguageHandler(i int, token nfp.Token) (err err
116
243
err = ErrUnsupportedNumberFormat
117
244
return
118
245
}
119
- if nf . localCode = part .Token .TValue ; nf . localCode != "409" {
246
+ if _ , ok := supportedLanguageInfo [ strings . ToUpper ( part .Token .TValue )]; ! ok {
120
247
err = ErrUnsupportedNumberFormat
121
248
return
122
249
}
250
+ nf .localCode = strings .ToUpper (part .Token .TValue )
123
251
}
124
252
return
125
253
}
126
254
255
+ // localAmPm return AM/PM name by supported language ID.
256
+ func (nf * numberFormat ) localAmPm (ap string ) string {
257
+ if languageInfo , ok := supportedLanguageInfo [nf .localCode ]; ok {
258
+ return languageInfo .apFmt
259
+ }
260
+ return ap
261
+ }
262
+
263
+ // localMonthsNameEnglish returns the English name of the month.
264
+ func localMonthsNameEnglish (t time.Time , abbr int ) string {
265
+ if abbr == 3 {
266
+ return t .Month ().String ()[:3 ]
267
+ }
268
+ if abbr == 4 {
269
+ return t .Month ().String ()
270
+ }
271
+ return t .Month ().String ()[:1 ]
272
+ }
273
+
274
+ // localMonthsNameAfrikaans returns the Afrikaans name of the month.
275
+ func localMonthsNameAfrikaans (t time.Time , abbr int ) string {
276
+ if abbr == 3 {
277
+ month := monthNamesAfrikaans [int (t .Month ())- 1 ]
278
+ if len ([]rune (month )) <= 3 {
279
+ return month
280
+ }
281
+ return string ([]rune (month )[:3 ]) + "."
282
+ }
283
+ if abbr == 4 {
284
+ return monthNamesAfrikaans [int (t .Month ())- 1 ]
285
+ }
286
+ return monthNamesAfrikaans [int (t .Month ())- 1 ][:1 ]
287
+ }
288
+
289
+ // localMonthsNameAustria returns the Austria name of the month.
290
+ func localMonthsNameAustria (t time.Time , abbr int ) string {
291
+ if abbr == 3 {
292
+ return string ([]rune (monthNamesAustria [int (t .Month ())- 1 ])[:3 ])
293
+ }
294
+ if abbr == 4 {
295
+ return monthNamesAustria [int (t .Month ())- 1 ]
296
+ }
297
+ return monthNamesAustria [int (t .Month ())- 1 ][:1 ]
298
+ }
299
+
300
+ // localMonthsNameBangla returns the German name of the month.
301
+ func localMonthsNameBangla (t time.Time , abbr int ) string {
302
+ if abbr == 3 || abbr == 4 {
303
+ return monthNamesBangla [int (t .Month ())- 1 ]
304
+ }
305
+ return string ([]rune (monthNamesBangla [int (t .Month ())- 1 ])[:1 ])
306
+ }
307
+
308
+ // localMonthsNameFrench returns the French name of the month.
309
+ func localMonthsNameFrench (t time.Time , abbr int ) string {
310
+ if abbr == 3 {
311
+ month := monthNamesFrench [int (t .Month ())- 1 ]
312
+ if len ([]rune (month )) <= 4 {
313
+ return month
314
+ }
315
+ return string ([]rune (month )[:4 ]) + "."
316
+ }
317
+ if abbr == 4 {
318
+ return monthNamesFrench [int (t .Month ())- 1 ]
319
+ }
320
+ return monthNamesFrench [int (t .Month ())- 1 ][:1 ]
321
+ }
322
+
323
+ // localMonthsNameItalian returns the Italian name of the month.
324
+ func localMonthsNameItalian (t time.Time , abbr int ) string {
325
+ if abbr == 3 {
326
+ return monthNamesItalian [int (t .Month ())- 1 ][:3 ]
327
+ }
328
+ if abbr == 4 {
329
+ return monthNamesItalian [int (t .Month ())- 1 ]
330
+ }
331
+ return monthNamesItalian [int (t .Month ())- 1 ][:1 ]
332
+ }
333
+
334
+ // localMonthsNameGerman returns the German name of the month.
335
+ func localMonthsNameGerman (t time.Time , abbr int ) string {
336
+ if abbr == 3 {
337
+ return string ([]rune (monthNamesGerman [int (t .Month ())- 1 ])[:3 ])
338
+ }
339
+ if abbr == 4 {
340
+ return monthNamesGerman [int (t .Month ())- 1 ]
341
+ }
342
+ return string ([]rune (monthNamesGerman [int (t .Month ())- 1 ])[:1 ])
343
+ }
344
+
345
+ // localMonthsNameChinese1 returns the Chinese name of the month.
346
+ func localMonthsNameChinese1 (t time.Time , abbr int ) string {
347
+ if abbr == 3 {
348
+ return strconv .Itoa (int (t .Month ())) + "月"
349
+ }
350
+ if abbr == 4 {
351
+ return monthNamesChinese [int (t .Month ())- 1 ] + "月"
352
+ }
353
+ return monthNamesChinese [int (t .Month ())- 1 ]
354
+ }
355
+
356
+ // localMonthsNameChinese2 returns the Chinese name of the month.
357
+ func localMonthsNameChinese2 (t time.Time , abbr int ) string {
358
+ if abbr == 3 || abbr == 4 {
359
+ return monthNamesChinese [int (t .Month ())- 1 ] + "月"
360
+ }
361
+ return monthNamesChinese [int (t .Month ())- 1 ]
362
+ }
363
+
364
+ // localMonthsNameChinese3 returns the Chinese name of the month.
365
+ func localMonthsNameChinese3 (t time.Time , abbr int ) string {
366
+ if abbr == 3 || abbr == 4 {
367
+ return strconv .Itoa (int (t .Month ())) + "月"
368
+ }
369
+ return strconv .Itoa (int (t .Month ()))
370
+ }
371
+
372
+ // localMonthsNameKorean returns the Korean name of the month.
373
+ func localMonthsNameKorean (t time.Time , abbr int ) string {
374
+ if abbr == 3 || abbr == 4 {
375
+ return strconv .Itoa (int (t .Month ())) + "월"
376
+ }
377
+ return strconv .Itoa (int (t .Month ()))
378
+ }
379
+
380
+ // localMonthName return months name by supported language ID.
381
+ func (nf * numberFormat ) localMonthsName (abbr int ) string {
382
+ if languageInfo , ok := supportedLanguageInfo [nf .localCode ]; ok {
383
+ return languageInfo .localMonth (nf .t , abbr )
384
+ }
385
+ return localMonthsNameEnglish (nf .t , abbr )
386
+ }
387
+
127
388
// dateTimesHandler will be handling date and times types tokens for a number
128
389
// format expression.
129
390
func (nf * numberFormat ) dateTimesHandler (i int , token nfp.Token ) {
130
391
if idx := inStrSlice (nfp .AmPm , strings .ToUpper (token .TValue ), false ); idx != - 1 {
131
392
if nf .ap == "" {
132
393
nextHours := nf .hoursNext (i )
133
- aps := strings .Split (token .TValue , "/" )
394
+ aps := strings .Split (nf . localAmPm ( token .TValue ) , "/" )
134
395
nf .ap = aps [0 ]
135
396
if nextHours > 12 {
136
397
nf .ap = aps [1 ]
@@ -150,15 +411,15 @@ func (nf *numberFormat) dateTimesHandler(i int, token nfp.Token) {
150
411
return
151
412
}
152
413
if l == 3 {
153
- nf .result += nf .t . Month (). String ()[: 3 ]
414
+ nf .result += nf .localMonthsName ( 3 )
154
415
return
155
416
}
156
417
if l == 4 || l > 5 {
157
- nf .result += nf .t . Month (). String ( )
418
+ nf .result += nf .localMonthsName ( 4 )
158
419
return
159
420
}
160
421
if l == 5 {
161
- nf .result += nf .t . Month (). String ()[: 1 ]
422
+ nf .result += nf .localMonthsName ( 5 )
162
423
return
163
424
}
164
425
}
@@ -304,7 +565,7 @@ func (nf *numberFormat) apNext(i int) ([]string, bool) {
304
565
return nil , false
305
566
}
306
567
if i := inStrSlice (nfp .AmPm , tokens [idx ].TValue , false ); i != - 1 {
307
- return strings .Split (tokens [idx ].TValue , "/" ), true
568
+ return strings .Split (nf . localAmPm ( tokens [idx ].TValue ) , "/" ), true
308
569
}
309
570
}
310
571
}
0 commit comments