Skip to content

Commit d1937a0

Browse files
authored
This closes qax-os#1885, add new CultureNameJaJP, CultureNameKoKR and CultureNameZhTW enumeration values (qax-os#1895)
- Support apply number format for the Japanese calendar years, the Korean Danki calendar and the Republic of China year - Update unit tests Signed-off-by: wushiling50 <[email protected]>
1 parent f1d1a5d commit d1937a0

File tree

4 files changed

+174
-33
lines changed

4 files changed

+174
-33
lines changed

calc.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -13629,7 +13629,9 @@ func (fn *formulaFuncs) DBCS(argsList *list.List) formulaArg {
1362913629
if arg.Type == ArgError {
1363013630
return arg
1363113631
}
13632-
if fn.f.options.CultureInfo == CultureNameZhCN {
13632+
if fn.f.options.CultureInfo == CultureNameJaJP ||
13633+
fn.f.options.CultureInfo == CultureNameZhCN ||
13634+
fn.f.options.CultureInfo == CultureNameZhTW {
1363313635
var chars []string
1363413636
for _, r := range arg.Value() {
1363513637
code := r
@@ -16378,7 +16380,10 @@ func (fn *formulaFuncs) DOLLAR(argsList *list.List) formulaArg {
1637816380
symbol := map[CultureName]string{
1637916381
CultureNameUnknown: "$",
1638016382
CultureNameEnUS: "$",
16383+
CultureNameJaJP: "¥",
16384+
CultureNameKoKR: "\u20a9",
1638116385
CultureNameZhCN: "¥",
16386+
CultureNameZhTW: "NT$",
1638216387
}[fn.f.options.CultureInfo]
1638316388
numFmtCode := fmt.Sprintf("%s#,##0%s%s;(%s#,##0%s%s)",
1638416389
symbol, dot, strings.Repeat("0", decimals), symbol, dot, strings.Repeat("0", decimals))

excelize_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,17 @@ func TestSetCellStyleCurrencyNumberFormat(t *testing.T) {
870870
}
871871

872872
func TestSetCellStyleLangNumberFormat(t *testing.T) {
873-
rawCellValues := [][]string{{"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}}
873+
rawCellValues := make([][]string, 42)
874+
for i := 0; i < 42; i++ {
875+
rawCellValues[i] = []string{"45162"}
876+
}
874877
for lang, expected := range map[CultureName][][]string{
875878
CultureNameUnknown: rawCellValues,
876879
CultureNameEnUS: {{"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"0:00:00"}, {"0:00:00"}, {"0:00:00"}, {"0:00:00"}, {"45162"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"8/24/23"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}},
880+
CultureNameJaJP: {{"R5.8.24"}, {"令和5年8月24日"}, {"令和5年8月24日"}, {"8/24/23"}, {"2023年8月24日"}, {"0時00分"}, {"0時00分00秒"}, {"2023年8月"}, {"8月24日"}, {"R5.8.24"}, {"R5.8.24"}, {"令和5年8月24日"}, {"2023年8月"}, {"8月24日"}, {"令和5年8月24日"}, {"2023年8月"}, {"8月24日"}, {"R5.8.24"}, {"令和5年8月24日"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}},
881+
CultureNameKoKR: [][]string{[]string{"4356年 08月 24日"}, []string{"08-24"}, []string{"08-24"}, []string{"08-24-56"}, []string{"4356년 08월 24일"}, []string{"0시 00분"}, []string{"0시 00분 00초"}, []string{"4356-08-24"}, []string{"4356-08-24"}, []string{"4356年 08月 24日"}, []string{"4356年 08月 24日"}, []string{"08-24"}, []string{"4356-08-24"}, []string{"4356-08-24"}, []string{"08-24"}, []string{"4356-08-24"}, []string{"4356-08-24"}, []string{"4356年 08月 24日"}, []string{"08-24"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}},
877882
CultureNameZhCN: {{"2023年8月"}, {"8月24日"}, {"8月24日"}, {"8/24/23"}, {"2023年8月24日"}, {"0时00分"}, {"0时00分00秒"}, {"上午12时00分"}, {"上午12时00分00秒"}, {"2023年8月"}, {"2023年8月"}, {"8月24日"}, {"2023年8月"}, {"8月24日"}, {"8月24日"}, {"上午12时00分"}, {"上午12时00分00秒"}, {"2023年8月"}, {"8月24日"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}},
883+
CultureNameZhTW: {{"112/8/24"}, {"112年8月24日"}, {"112年8月24日"}, {"8/24/23"}, {"2023年8月24日"}, {"00時00分"}, {"00時00分00秒"}, {"上午12時00分"}, {"上午12時00分00秒"}, {"112/8/24"}, {"112/8/24"}, {"112年8月24日"}, {"上午12時00分"}, {"上午12時00分00秒"}, {"112年8月24日"}, {"上午12時00分"}, {"上午12時00分00秒"}, {"112/8/24"}, {"112年8月24日"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}},
878884
} {
879885
f, err := prepareTestBook5(Options{CultureInfo: lang})
880886
assert.NoError(t, err)
@@ -886,7 +892,10 @@ func TestSetCellStyleLangNumberFormat(t *testing.T) {
886892
// Test apply language number format code with date and time pattern
887893
for lang, expected := range map[CultureName][][]string{
888894
CultureNameEnUS: {{"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"00:00:00"}, {"00:00:00"}, {"00:00:00"}, {"00:00:00"}, {"45162"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"2023-8-24"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}},
895+
CultureNameJaJP: {{"R5.8.24"}, {"令和5年8月24日"}, {"令和5年8月24日"}, {"2023-8-24"}, {"2023年8月24日"}, {"00:00:00"}, {"00:00:00"}, {"2023年8月"}, {"8月24日"}, {"R5.8.24"}, {"R5.8.24"}, {"令和5年8月24日"}, {"2023年8月"}, {"8月24日"}, {"令和5年8月24日"}, {"2023年8月"}, {"8月24日"}, {"R5.8.24"}, {"令和5年8月24日"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}},
896+
CultureNameKoKR: [][]string{[]string{"4356年 08月 24日"}, []string{"08-24"}, []string{"08-24"}, []string{"4356-8-24"}, []string{"4356년 08월 24일"}, []string{"00:00:00"}, []string{"00:00:00"}, []string{"4356-08-24"}, []string{"4356-08-24"}, []string{"4356年 08月 24日"}, []string{"4356年 08月 24日"}, []string{"08-24"}, []string{"4356-08-24"}, []string{"4356-08-24"}, []string{"08-24"}, []string{"4356-08-24"}, []string{"4356-08-24"}, []string{"4356年 08月 24日"}, []string{"08-24"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}, []string{"45162"}},
889897
CultureNameZhCN: {{"2023年8月"}, {"8月24日"}, {"8月24日"}, {"2023-8-24"}, {"2023年8月24日"}, {"00:00:00"}, {"00:00:00"}, {"上午12时00分"}, {"上午12时00分00秒"}, {"2023年8月"}, {"2023年8月"}, {"8月24日"}, {"2023年8月"}, {"8月24日"}, {"8月24日"}, {"上午12时00分"}, {"上午12时00分00秒"}, {"2023年8月"}, {"8月24日"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}},
898+
CultureNameZhTW: {{"112/8/24"}, {"112年8月24日"}, {"112年8月24日"}, {"2023-8-24"}, {"2023年8月24日"}, {"00:00:00"}, {"00:00:00"}, {"上午12時00分"}, {"上午12時00分00秒"}, {"112/8/24"}, {"112/8/24"}, {"112年8月24日"}, {"上午12時00分"}, {"上午12時00分00秒"}, {"112年8月24日"}, {"上午12時00分"}, {"上午12時00分00秒"}, {"112/8/24"}, {"112年8月24日"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}, {"45162"}},
890899
} {
891900
f, err := prepareTestBook5(Options{CultureInfo: lang, ShortDatePattern: "yyyy-M-d", LongTimePattern: "hh:mm:ss"})
892901
assert.NoError(t, err)

numfmt.go

+141-31
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ type CultureName byte
5757
const (
5858
CultureNameUnknown CultureName = iota
5959
CultureNameEnUS
60+
CultureNameJaJP
61+
CultureNameKoKR
6062
CultureNameZhCN
63+
CultureNameZhTW
6164
)
6265

6366
var (
@@ -791,7 +794,7 @@ var (
791794
31748: {tags: []string{"zh-Hant"}, localMonth: localMonthsNameChinese3, apFmt: nfp.AmPm[2], weekdayNames: weekdayNamesChinese, weekdayNamesAbbr: weekdayNamesChineseAbbr2},
792795
3076: {tags: []string{"zh-HK"}, localMonth: localMonthsNameChinese2, apFmt: nfp.AmPm[2], weekdayNames: weekdayNamesChinese, weekdayNamesAbbr: weekdayNamesChineseAbbr2},
793796
5124: {tags: []string{"zh-MO"}, localMonth: localMonthsNameChinese3, apFmt: nfp.AmPm[2], weekdayNames: weekdayNamesChinese, weekdayNamesAbbr: weekdayNamesChineseAbbr2},
794-
1028: {tags: []string{"zh-TW"}, localMonth: localMonthsNameChinese3, apFmt: nfp.AmPm[2], weekdayNames: weekdayNamesChinese, weekdayNamesAbbr: weekdayNamesChineseAbbr2},
797+
1028: {tags: []string{"zh-TW"}, localMonth: localMonthsNameChinese3, apFmt: nfp.AmPm[2], weekdayNames: weekdayNamesChinese, weekdayNamesAbbr: weekdayNamesChineseAbbr2, useGannen: true},
795798
9: {tags: []string{"en"}, localMonth: localMonthsNameEnglish, apFmt: nfp.AmPm[0], weekdayNames: weekdayNamesEnglish, weekdayNamesAbbr: weekdayNamesEnglishAbbr},
796799
4096: {tags: []string{
797800
"aa", "aa-DJ", "aa-ER", "aa-ER", "aa-NA", "agq", "agq-CM", "ak", "ak-GH", "sq-ML",
@@ -1168,6 +1171,10 @@ var (
11681171
"JA-JP-X-GANNEN": {tags: []string{"ja-JP"}, localMonth: localMonthsNameChinese3, apFmt: apFmtJapanese, weekdayNames: weekdayNamesJapanese, weekdayNamesAbbr: weekdayNamesJapaneseAbbr},
11691172
"JA-JP-X-GANNEN,80": {tags: []string{"ja-JP"}, localMonth: localMonthsNameChinese3, apFmt: apFmtJapanese, weekdayNames: weekdayNamesJapanese, weekdayNamesAbbr: weekdayNamesJapaneseAbbr, useGannen: true},
11701173
}
1174+
// republicOfChinaYear defined start time of the Republic of China
1175+
republicOfChinaYear = time.Date(1912, time.January, 1, 0, 0, 0, 0, time.UTC)
1176+
// republicOfChinaEraName defined the Republic of China era name for the Republic of China calendar.
1177+
republicOfChinaEraName = []string{"\u4e2d\u83ef\u6c11\u570b", "\u6c11\u570b", "\u524d"}
11711178
// japaneseEraYears list the Japanese era name periods.
11721179
japaneseEraYears = []time.Time{
11731180
time.Date(1868, time.August, 8, 0, 0, 0, 0, time.UTC),
@@ -4634,6 +4641,24 @@ var (
46344641
return r.Replace(s)
46354642
},
46364643
}
4644+
// langNumFmtFunc defines functions to apply language number format code.
4645+
langNumFmtFunc = map[CultureName]func(f *File, numFmtID int) string{
4646+
CultureNameEnUS: func(f *File, numFmtID int) string {
4647+
return f.langNumFmtFuncEnUS(numFmtID)
4648+
},
4649+
CultureNameJaJP: func(f *File, numFmtID int) string {
4650+
return f.langNumFmtFuncJaJP(numFmtID)
4651+
},
4652+
CultureNameKoKR: func(f *File, numFmtID int) string {
4653+
return f.langNumFmtFuncKoKR(numFmtID)
4654+
},
4655+
CultureNameZhCN: func(f *File, numFmtID int) string {
4656+
return f.langNumFmtFuncZhCN(numFmtID)
4657+
},
4658+
CultureNameZhTW: func(f *File, numFmtID int) string {
4659+
return f.langNumFmtFuncZhTW(numFmtID)
4660+
},
4661+
}
46374662
)
46384663

46394664
// getSupportedLanguageInfo returns language infomation by giving language code.
@@ -4694,6 +4719,54 @@ func (f *File) langNumFmtFuncEnUS(numFmtID int) string {
46944719
return ""
46954720
}
46964721

4722+
// langNumFmtFuncJaJP returns number format code by given date and time pattern
4723+
// for country code ja-jp.
4724+
func (f *File) langNumFmtFuncJaJP(numFmtID int) string {
4725+
if numFmtID == 30 && f.options.ShortDatePattern != "" {
4726+
return f.options.ShortDatePattern
4727+
}
4728+
if (32 <= numFmtID && numFmtID <= 33) && f.options.LongTimePattern != "" {
4729+
return f.options.LongTimePattern
4730+
}
4731+
return langNumFmt["ja-jp"][numFmtID]
4732+
}
4733+
4734+
// langNumFmtFuncKoKR returns number format code by given date and time pattern
4735+
// for country code ko-kr.
4736+
func (f *File) langNumFmtFuncKoKR(numFmtID int) string {
4737+
if numFmtID == 30 && f.options.ShortDatePattern != "" {
4738+
return f.options.ShortDatePattern
4739+
}
4740+
if (32 <= numFmtID && numFmtID <= 33) && f.options.LongTimePattern != "" {
4741+
return f.options.LongTimePattern
4742+
}
4743+
return langNumFmt["ko-kr"][numFmtID]
4744+
}
4745+
4746+
// langNumFmtFuncZhCN returns number format code by given date and time pattern
4747+
// for country code zh-cn.
4748+
func (f *File) langNumFmtFuncZhCN(numFmtID int) string {
4749+
if numFmtID == 30 && f.options.ShortDatePattern != "" {
4750+
return f.options.ShortDatePattern
4751+
}
4752+
if (32 <= numFmtID && numFmtID <= 33) && f.options.LongTimePattern != "" {
4753+
return f.options.LongTimePattern
4754+
}
4755+
return langNumFmt["zh-cn"][numFmtID]
4756+
}
4757+
4758+
// langNumFmtFuncZhTW returns number format code by given date and time pattern
4759+
// for country code zh-tw.
4760+
func (f *File) langNumFmtFuncZhTW(numFmtID int) string {
4761+
if numFmtID == 30 && f.options.ShortDatePattern != "" {
4762+
return f.options.ShortDatePattern
4763+
}
4764+
if (32 <= numFmtID && numFmtID <= 33) && f.options.LongTimePattern != "" {
4765+
return f.options.LongTimePattern
4766+
}
4767+
return langNumFmt["zh-tw"][numFmtID]
4768+
}
4769+
46974770
// checkDateTimePattern check and validate date and time options field value.
46984771
func (f *File) checkDateTimePattern() error {
46994772
for _, pattern := range []string{f.options.LongDatePattern, f.options.LongTimePattern, f.options.ShortDatePattern} {
@@ -4770,30 +4843,15 @@ func (f *File) extractNumFmtDecimal(fmtCode string) int {
47704843
return -1
47714844
}
47724845

4773-
// langNumFmtFuncZhCN returns number format code by given date and time pattern
4774-
// for country code zh-cn.
4775-
func (f *File) langNumFmtFuncZhCN(numFmtID int) string {
4776-
if numFmtID == 30 && f.options.ShortDatePattern != "" {
4777-
return f.options.ShortDatePattern
4778-
}
4779-
if (32 <= numFmtID && numFmtID <= 33) && f.options.LongTimePattern != "" {
4780-
return f.options.LongTimePattern
4781-
}
4782-
return langNumFmt["zh-cn"][numFmtID]
4783-
}
4784-
47854846
// getBuiltInNumFmtCode convert number format index to number format code with
47864847
// specified locale and language.
47874848
func (f *File) getBuiltInNumFmtCode(numFmtID int) (string, bool) {
47884849
if fmtCode, ok := builtInNumFmt[numFmtID]; ok {
47894850
return fmtCode, true
47904851
}
47914852
if isLangNumFmt(numFmtID) {
4792-
if f.options.CultureInfo == CultureNameEnUS {
4793-
return f.langNumFmtFuncEnUS(numFmtID), true
4794-
}
4795-
if f.options.CultureInfo == CultureNameZhCN {
4796-
return f.langNumFmtFuncZhCN(numFmtID), true
4853+
if fn, ok := langNumFmtFunc[f.options.CultureInfo]; ok {
4854+
return fn(f, numFmtID), true
47974855
}
47984856
}
47994857
return "", false
@@ -6912,23 +6970,13 @@ func eraYear(t time.Time) (int, int) {
69126970
return i, year
69136971
}
69146972

6915-
// yearsHandler will be handling years in the date and times types tokens for a
6916-
// number format expression.
6917-
func (nf *numberFormat) yearsHandler(token nfp.Token) {
6918-
if strings.Contains(strings.ToUpper(token.TValue), "Y") {
6919-
if len(token.TValue) <= 2 {
6920-
nf.result += strconv.Itoa(nf.t.Year())[2:]
6921-
return
6922-
}
6923-
nf.result += strconv.Itoa(nf.t.Year())
6924-
return
6925-
}
6973+
// japaneseYearHandler handling the Japanease calendar years.
6974+
func (nf *numberFormat) japaneseYearHandler(token nfp.Token, langInfo languageInfo) {
69266975
if strings.Contains(strings.ToUpper(token.TValue), "G") {
69276976
i, year := eraYear(nf.t)
69286977
if year == -1 {
69296978
return
69306979
}
6931-
langInfo, _ := getSupportedLanguageInfo(nf.localCode)
69326980
nf.useGannen = langInfo.useGannen
69336981
switch len(token.TValue) {
69346982
case 1:
@@ -6939,7 +6987,6 @@ func (nf *numberFormat) yearsHandler(token nfp.Token) {
69396987
default:
69406988
nf.result += japaneseEraNames[i]
69416989
}
6942-
return
69436990
}
69446991
if strings.Contains(strings.ToUpper(token.TValue), "E") {
69456992
_, year := eraYear(nf.t)
@@ -6961,6 +7008,69 @@ func (nf *numberFormat) yearsHandler(token nfp.Token) {
69617008
}
69627009
}
69637010

7011+
// republicOfChinaYearHandler handling the Republic of China calendar years.
7012+
func (nf *numberFormat) republicOfChinaYearHandler(token nfp.Token, langInfo languageInfo) {
7013+
if strings.Contains(strings.ToUpper(token.TValue), "G") {
7014+
year := nf.t.Year() - republicOfChinaYear.Year() + 1
7015+
if year == 1 {
7016+
nf.useGannen = langInfo.useGannen
7017+
}
7018+
var name string
7019+
if name = republicOfChinaEraName[0]; len(token.TValue) < 3 {
7020+
name = republicOfChinaEraName[1]
7021+
}
7022+
if year < 0 {
7023+
name += republicOfChinaEraName[2]
7024+
}
7025+
nf.result += name
7026+
}
7027+
if strings.Contains(strings.ToUpper(token.TValue), "E") {
7028+
year := nf.t.Year() - republicOfChinaYear.Year() + 1
7029+
if year < 0 {
7030+
year = republicOfChinaYear.Year() - nf.t.Year()
7031+
}
7032+
if year == 1 && nf.useGannen {
7033+
nf.result += "\u5143"
7034+
return
7035+
}
7036+
if len(token.TValue) == 1 && !nf.useGannen {
7037+
nf.result += strconv.Itoa(year)
7038+
}
7039+
}
7040+
}
7041+
7042+
// yearsHandler will be handling years in the date and times types tokens for a
7043+
// number format expression.
7044+
func (nf *numberFormat) yearsHandler(token nfp.Token) {
7045+
langInfo, _ := getSupportedLanguageInfo(nf.localCode)
7046+
if strings.Contains(strings.ToUpper(token.TValue), "Y") {
7047+
year := nf.t.Year()
7048+
if nf.opts != nil && nf.opts.CultureInfo == CultureNameKoKR {
7049+
year += 2333
7050+
}
7051+
if len(token.TValue) <= 2 {
7052+
nf.result += strconv.Itoa(year)[2:]
7053+
return
7054+
}
7055+
nf.result += strconv.Itoa(year)
7056+
return
7057+
}
7058+
if inStrSlice(langInfo.tags, "zh-TW", false) != -1 ||
7059+
nf.opts != nil && nf.opts.CultureInfo == CultureNameZhTW {
7060+
nf.republicOfChinaYearHandler(token, langInfo)
7061+
return
7062+
}
7063+
if inStrSlice(langInfo.tags, "ja-JP", false) != -1 ||
7064+
nf.opts != nil && nf.opts.CultureInfo == CultureNameJaJP {
7065+
nf.japaneseYearHandler(token, langInfo)
7066+
return
7067+
}
7068+
if strings.Contains(strings.ToUpper(token.TValue), "E") {
7069+
nf.result += strconv.Itoa(nf.t.Year())
7070+
return
7071+
}
7072+
}
7073+
69647074
// daysHandler will be handling days in the date and times types tokens for a
69657075
// number format expression.
69667076
func (nf *numberFormat) daysHandler(token nfp.Token) {

0 commit comments

Comments
 (0)