@@ -33,18 +33,18 @@ type languageInfo struct {
33
33
// numberFormat directly maps the number format parser runtime required
34
34
// fields.
35
35
type numberFormat struct {
36
- opts * Options
37
- cellType CellType
38
- section []nfp.Section
39
- t time.Time
40
- sectionIdx int
41
- date1904 , isNumeric , hours , seconds , useMillisecond bool
42
- number float64
43
- ap , localCode , result , value , valueSectionType string
44
- switchArgument , currencyString string
45
- fracHolder , fracPadding , intHolder , intPadding , expBaseLen int
46
- percent int
47
- useCommaSep , usePointer , usePositive , useScientificNotation bool
36
+ opts * Options
37
+ cellType CellType
38
+ section []nfp.Section
39
+ t time.Time
40
+ sectionIdx int
41
+ date1904 , isNumeric , hours , seconds , useMillisecond , useGannen bool
42
+ number float64
43
+ ap , localCode , result , value , valueSectionType string
44
+ switchArgument , currencyString string
45
+ fracHolder , fracPadding , intHolder , intPadding , expBaseLen int
46
+ percent int
47
+ useCommaSep , usePointer , usePositive , useScientificNotation bool
48
48
}
49
49
50
50
// CultureName is the type of supported language country codes types for apply
@@ -797,6 +797,7 @@ var (
797
797
"11" : {tags : []string {"ja" }, localMonth : localMonthsNameChinese3 , apFmt : apFmtJapanese },
798
798
"411" : {tags : []string {"ja-JP" }, localMonth : localMonthsNameChinese3 , apFmt : apFmtJapanese },
799
799
"800411" : {tags : []string {"ja-JP" }, localMonth : localMonthsNameChinese3 , apFmt : apFmtJapanese },
800
+ "JP-X-GANNEN" : {tags : []string {"ja-JP" }, localMonth : localMonthsNameChinese3 , apFmt : apFmtJapanese },
800
801
"JP-X-GANNEN,80" : {tags : []string {"ja-JP" }, localMonth : localMonthsNameChinese3 , apFmt : apFmtJapanese , useGannen : true },
801
802
"12" : {tags : []string {"ko" }, localMonth : localMonthsNameKorean , apFmt : apFmtKorean },
802
803
"412" : {tags : []string {"ko-KR" }, localMonth : localMonthsNameKorean , apFmt : apFmtKorean },
@@ -1344,7 +1345,7 @@ func (nf *numberFormat) dateTimeHandler() string {
1344
1345
if changeNumFmtCode , err := nf .currencyLanguageHandler (token ); err != nil || changeNumFmtCode {
1345
1346
return nf .value
1346
1347
}
1347
- if ! supportedLanguageInfo [ nf .localCode ]. useGannen {
1348
+ if ! strings . EqualFold ( nf .localCode , "JP-X-GANNEN" ) && ! strings . EqualFold ( nf . localCode , "JP-X-GANNEN,80" ) {
1348
1349
nf .result += nf .currencyString
1349
1350
}
1350
1351
}
@@ -1766,6 +1767,18 @@ func (nf *numberFormat) dateTimesHandler(i int, token nfp.Token) {
1766
1767
nf .secondsHandler (token )
1767
1768
}
1768
1769
1770
+ // eraYear convert time to the Japanese era years.
1771
+ func eraYear (t time.Time ) (int , int ) {
1772
+ i , year := 0 , - 1
1773
+ for i = len (japaneseEraYears ) - 1 ; i > 0 ; i -- {
1774
+ if y := japaneseEraYears [i ]; t .After (y ) {
1775
+ year = t .Year () - y .Year () + 1
1776
+ break
1777
+ }
1778
+ }
1779
+ return i , year
1780
+ }
1781
+
1769
1782
// yearsHandler will be handling years in the date and times types tokens for a
1770
1783
// number format expression.
1771
1784
func (nf * numberFormat ) yearsHandler (token nfp.Token ) {
@@ -1778,24 +1791,38 @@ func (nf *numberFormat) yearsHandler(token nfp.Token) {
1778
1791
return
1779
1792
}
1780
1793
if strings .Contains (strings .ToUpper (token .TValue ), "G" ) {
1781
- for i := len (japaneseEraYears ) - 1 ; i > 0 ; i -- {
1782
- if y := japaneseEraYears [i ]; nf .t .After (y ) {
1783
- switch len (token .TValue ) {
1784
- case 1 :
1785
- nf .result += japaneseEraSymbols [i ]
1786
- case 2 :
1787
- nf .result += japaneseEraNames [i ][:3 ]
1788
- default :
1789
- nf .result += japaneseEraNames [i ]
1790
- }
1791
- year := nf .t .Year () - y .Year () + 1
1792
- if year == 1 && len (token .TValue ) > 1 && supportedLanguageInfo [nf .localCode ].useGannen {
1793
- nf .result += "\u5143 "
1794
- break
1795
- }
1796
- nf .result += strconv .Itoa (year )
1797
- break
1798
- }
1794
+ i , year := eraYear (nf .t )
1795
+ if year == - 1 {
1796
+ return
1797
+ }
1798
+ nf .useGannen = supportedLanguageInfo [nf .localCode ].useGannen
1799
+ switch len (token .TValue ) {
1800
+ case 1 :
1801
+ nf .useGannen = false
1802
+ nf .result += japaneseEraSymbols [i ]
1803
+ case 2 :
1804
+ nf .result += japaneseEraNames [i ][:3 ]
1805
+ default :
1806
+ nf .result += japaneseEraNames [i ]
1807
+ }
1808
+ return
1809
+ }
1810
+ if strings .Contains (strings .ToUpper (token .TValue ), "E" ) {
1811
+ _ , year := eraYear (nf .t )
1812
+ if year == - 1 {
1813
+ nf .result += strconv .Itoa (nf .t .Year ())
1814
+ return
1815
+ }
1816
+ if year == 1 && nf .useGannen {
1817
+ nf .result += "\u5143 "
1818
+ return
1819
+ }
1820
+ if len (token .TValue ) == 1 && ! nf .useGannen {
1821
+ nf .result += strconv .Itoa (year )
1822
+ return
1823
+ }
1824
+ if len (token .TValue ) == 2 {
1825
+ nf .result += fmt .Sprintf ("%02d" , year )
1799
1826
}
1800
1827
}
1801
1828
}
0 commit comments