Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
aa3c79a8
excelize
项目概览
xuri
/
excelize
通知
13
Star
2
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
excelize
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
已验证
提交
aa3c79a8
编写于
8月 01, 2023
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support apply number format with the Japanese era years
上级
5fe30eb4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
31 deletion
+71
-31
numfmt.go
numfmt.go
+58
-31
numfmt_test.go
numfmt_test.go
+13
-0
未找到文件。
numfmt.go
浏览文件 @
aa3c79a8
...
@@ -33,18 +33,18 @@ type languageInfo struct {
...
@@ -33,18 +33,18 @@ type languageInfo struct {
// numberFormat directly maps the number format parser runtime required
// numberFormat directly maps the number format parser runtime required
// fields.
// fields.
type
numberFormat
struct
{
type
numberFormat
struct
{
opts
*
Options
opts
*
Options
cellType
CellType
cellType
CellType
section
[]
nfp
.
Section
section
[]
nfp
.
Section
t
time
.
Time
t
time
.
Time
sectionIdx
int
sectionIdx
int
date1904
,
isNumeric
,
hours
,
seconds
,
useMillisecond
bool
date1904
,
isNumeric
,
hours
,
seconds
,
useMillisecond
,
useGannen
bool
number
float64
number
float64
ap
,
localCode
,
result
,
value
,
valueSectionType
string
ap
,
localCode
,
result
,
value
,
valueSectionType
string
switchArgument
,
currencyString
string
switchArgument
,
currencyString
string
fracHolder
,
fracPadding
,
intHolder
,
intPadding
,
expBaseLen
int
fracHolder
,
fracPadding
,
intHolder
,
intPadding
,
expBaseLen
int
percent
int
percent
int
useCommaSep
,
usePointer
,
usePositive
,
useScientificNotation
bool
useCommaSep
,
usePointer
,
usePositive
,
useScientificNotation
bool
}
}
// CultureName is the type of supported language country codes types for apply
// CultureName is the type of supported language country codes types for apply
...
@@ -797,6 +797,7 @@ var (
...
@@ -797,6 +797,7 @@ var (
"11"
:
{
tags
:
[]
string
{
"ja"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
},
"11"
:
{
tags
:
[]
string
{
"ja"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
},
"411"
:
{
tags
:
[]
string
{
"ja-JP"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
},
"411"
:
{
tags
:
[]
string
{
"ja-JP"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
},
"800411"
:
{
tags
:
[]
string
{
"ja-JP"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
},
"800411"
:
{
tags
:
[]
string
{
"ja-JP"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
},
"JP-X-GANNEN"
:
{
tags
:
[]
string
{
"ja-JP"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
},
"JP-X-GANNEN,80"
:
{
tags
:
[]
string
{
"ja-JP"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
,
useGannen
:
true
},
"JP-X-GANNEN,80"
:
{
tags
:
[]
string
{
"ja-JP"
},
localMonth
:
localMonthsNameChinese3
,
apFmt
:
apFmtJapanese
,
useGannen
:
true
},
"12"
:
{
tags
:
[]
string
{
"ko"
},
localMonth
:
localMonthsNameKorean
,
apFmt
:
apFmtKorean
},
"12"
:
{
tags
:
[]
string
{
"ko"
},
localMonth
:
localMonthsNameKorean
,
apFmt
:
apFmtKorean
},
"412"
:
{
tags
:
[]
string
{
"ko-KR"
},
localMonth
:
localMonthsNameKorean
,
apFmt
:
apFmtKorean
},
"412"
:
{
tags
:
[]
string
{
"ko-KR"
},
localMonth
:
localMonthsNameKorean
,
apFmt
:
apFmtKorean
},
...
@@ -1344,7 +1345,7 @@ func (nf *numberFormat) dateTimeHandler() string {
...
@@ -1344,7 +1345,7 @@ func (nf *numberFormat) dateTimeHandler() string {
if
changeNumFmtCode
,
err
:=
nf
.
currencyLanguageHandler
(
token
);
err
!=
nil
||
changeNumFmtCode
{
if
changeNumFmtCode
,
err
:=
nf
.
currencyLanguageHandler
(
token
);
err
!=
nil
||
changeNumFmtCode
{
return
nf
.
value
return
nf
.
value
}
}
if
!
s
upportedLanguageInfo
[
nf
.
localCode
]
.
useGannen
{
if
!
s
trings
.
EqualFold
(
nf
.
localCode
,
"JP-X-GANNEN"
)
&&
!
strings
.
EqualFold
(
nf
.
localCode
,
"JP-X-GANNEN,80"
)
{
nf
.
result
+=
nf
.
currencyString
nf
.
result
+=
nf
.
currencyString
}
}
}
}
...
@@ -1766,6 +1767,18 @@ func (nf *numberFormat) dateTimesHandler(i int, token nfp.Token) {
...
@@ -1766,6 +1767,18 @@ func (nf *numberFormat) dateTimesHandler(i int, token nfp.Token) {
nf
.
secondsHandler
(
token
)
nf
.
secondsHandler
(
token
)
}
}
// eraYear convert time to the Japanese era years.
func
eraYear
(
t
time
.
Time
)
(
int
,
int
)
{
i
,
year
:=
0
,
-
1
for
i
=
len
(
japaneseEraYears
)
-
1
;
i
>
0
;
i
--
{
if
y
:=
japaneseEraYears
[
i
];
t
.
After
(
y
)
{
year
=
t
.
Year
()
-
y
.
Year
()
+
1
break
}
}
return
i
,
year
}
// yearsHandler will be handling years in the date and times types tokens for a
// yearsHandler will be handling years in the date and times types tokens for a
// number format expression.
// number format expression.
func
(
nf
*
numberFormat
)
yearsHandler
(
token
nfp
.
Token
)
{
func
(
nf
*
numberFormat
)
yearsHandler
(
token
nfp
.
Token
)
{
...
@@ -1778,24 +1791,38 @@ func (nf *numberFormat) yearsHandler(token nfp.Token) {
...
@@ -1778,24 +1791,38 @@ func (nf *numberFormat) yearsHandler(token nfp.Token) {
return
return
}
}
if
strings
.
Contains
(
strings
.
ToUpper
(
token
.
TValue
),
"G"
)
{
if
strings
.
Contains
(
strings
.
ToUpper
(
token
.
TValue
),
"G"
)
{
for
i
:=
len
(
japaneseEraYears
)
-
1
;
i
>
0
;
i
--
{
i
,
year
:=
eraYear
(
nf
.
t
)
if
y
:=
japaneseEraYears
[
i
];
nf
.
t
.
After
(
y
)
{
if
year
==
-
1
{
switch
len
(
token
.
TValue
)
{
return
case
1
:
}
nf
.
result
+=
japaneseEraSymbols
[
i
]
nf
.
useGannen
=
supportedLanguageInfo
[
nf
.
localCode
]
.
useGannen
case
2
:
switch
len
(
token
.
TValue
)
{
nf
.
result
+=
japaneseEraNames
[
i
][
:
3
]
case
1
:
default
:
nf
.
useGannen
=
false
nf
.
result
+=
japaneseEraNames
[
i
]
nf
.
result
+=
japaneseEraSymbols
[
i
]
}
case
2
:
year
:=
nf
.
t
.
Year
()
-
y
.
Year
()
+
1
nf
.
result
+=
japaneseEraNames
[
i
][
:
3
]
if
year
==
1
&&
len
(
token
.
TValue
)
>
1
&&
supportedLanguageInfo
[
nf
.
localCode
]
.
useGannen
{
default
:
nf
.
result
+=
"
\u5143
"
nf
.
result
+=
japaneseEraNames
[
i
]
break
}
}
return
nf
.
result
+=
strconv
.
Itoa
(
year
)
}
break
if
strings
.
Contains
(
strings
.
ToUpper
(
token
.
TValue
),
"E"
)
{
}
_
,
year
:=
eraYear
(
nf
.
t
)
if
year
==
-
1
{
nf
.
result
+=
strconv
.
Itoa
(
nf
.
t
.
Year
())
return
}
if
year
==
1
&&
nf
.
useGannen
{
nf
.
result
+=
"
\u5143
"
return
}
if
len
(
token
.
TValue
)
==
1
&&
!
nf
.
useGannen
{
nf
.
result
+=
strconv
.
Itoa
(
year
)
return
}
if
len
(
token
.
TValue
)
==
2
{
nf
.
result
+=
fmt
.
Sprintf
(
"%02d"
,
year
)
}
}
}
}
}
}
...
...
numfmt_test.go
浏览文件 @
aa3c79a8
...
@@ -420,12 +420,25 @@ func TestNumFmt(t *testing.T) {
...
@@ -420,12 +420,25 @@ func TestNumFmt(t *testing.T) {
{
"44835.18957170139"
,
"[$-41E]mmmmm dd yyyy h:mm AM/PM"
,
"
\u0e15
01 2022 4:32 AM"
},
{
"44835.18957170139"
,
"[$-41E]mmmmm dd yyyy h:mm AM/PM"
,
"
\u0e15
01 2022 4:32 AM"
},
{
"44866.18957170139"
,
"[$-41E]mmmmm dd yyyy h:mm AM/PM"
,
"
\u0e1e
01 2022 4:32 AM"
},
{
"44866.18957170139"
,
"[$-41E]mmmmm dd yyyy h:mm AM/PM"
,
"
\u0e1e
01 2022 4:32 AM"
},
{
"44896.18957170139"
,
"[$-41E]mmmmm dd yyyy h:mm AM/PM"
,
"
\u0e18
01 2022 4:32 AM"
},
{
"44896.18957170139"
,
"[$-41E]mmmmm dd yyyy h:mm AM/PM"
,
"
\u0e18
01 2022 4:32 AM"
},
{
"100"
,
"[$-411]ge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"1900年4月9日"
},
{
"43709"
,
"[$-411]ge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"R1年9月1日"
},
{
"43709"
,
"[$-411]ge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"R1年9月1日"
},
{
"43709"
,
"[$-411]gge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4
1年9月1日"
},
{
"43709"
,
"[$-411]gge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4
1年9月1日"
},
{
"43709"
,
"[$-411]ggge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u548C
1年9月1日"
},
{
"43709"
,
"[$-411]ggge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u548C
1年9月1日"
},
{
"43709"
,
"[$-411]gee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"R01年9月1日"
},
{
"43709"
,
"[$-411]ggee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4
01年9月1日"
},
{
"43709"
,
"[$-411]gggee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u548C
01年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen]ge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"R1年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen]gge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4
1年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen]ggge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u548C
1年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen]gee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"R01年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen]ggee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4
01年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen]gggee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u548C
01年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]ge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"R1年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]ge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"R1年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]gge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u5143
年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]gge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u5143
年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]ggge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u548C\u5143
年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]ggge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u548C\u5143
年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]gee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"R01年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]ggee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u5143
年9月1日"
},
{
"43709"
,
"[$-ja-JP-x-gannen,80]gggee
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u4EE4\u548C\u5143
年9月1日"
},
{
"43466.189571759256"
,
"[$-411]ge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"H31年1月1日"
},
{
"43466.189571759256"
,
"[$-411]ge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"H31年1月1日"
},
{
"43466.189571759256"
,
"[$-411]gge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u5E73
31年1月1日"
},
{
"43466.189571759256"
,
"[$-411]gge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u5E73
31年1月1日"
},
{
"43466.189571759256"
,
"[$-411]ggge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u5E73\u6210
31年1月1日"
},
{
"43466.189571759256"
,
"[$-411]ggge
\"
年
\"
m
\"
月
\"
d
\"
日
\"
;@"
,
"
\u5E73\u6210
31年1月1日"
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录