Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
c8c62c2d
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 搜索 >>
未验证
提交
c8c62c2d
编写于
5月 15, 2021
作者:
I
ice
提交者:
GitHub
5月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* This closes #841, fix incorrect build number format in PR #839
上级
37342f6d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
9 deletion
+22
-9
styles.go
styles.go
+14
-9
styles_test.go
styles_test.go
+8
-0
未找到文件。
styles.go
浏览文件 @
c8c62c2d
...
...
@@ -46,8 +46,8 @@ var builtInNumFmt = map[int]string{
17
:
"mmm-yy"
,
18
:
"h:mm am/pm"
,
19
:
"h:mm:ss am/pm"
,
20
:
"h:mm"
,
21
:
"h:mm:ss"
,
20
:
"h
h
:mm"
,
21
:
"h
h
:mm:ss"
,
22
:
"m/d/yy hh:mm"
,
37
:
"#,##0 ;(#,##0)"
,
38
:
"#,##0 ;[red](#,##0)"
,
...
...
@@ -1009,6 +1009,10 @@ func parseTime(v string, format string) string {
}
// It is the presence of the "am/pm" indicator that determines if this is
// a 12 hour or 24 hours time format, not the number of 'h' characters.
var
padding
bool
if
val
.
Hour
()
==
0
&&
!
strings
.
Contains
(
format
,
"hh"
)
&&
!
strings
.
Contains
(
format
,
"HH"
)
{
padding
=
true
}
if
is12HourTime
(
format
)
{
goFmt
=
strings
.
Replace
(
goFmt
,
"hh"
,
"3"
,
1
)
goFmt
=
strings
.
Replace
(
goFmt
,
"h"
,
"3"
,
1
)
...
...
@@ -1016,15 +1020,12 @@ func parseTime(v string, format string) string {
goFmt
=
strings
.
Replace
(
goFmt
,
"H"
,
"3"
,
1
)
}
else
{
goFmt
=
strings
.
Replace
(
goFmt
,
"hh"
,
"15"
,
1
)
if
val
.
Hour
()
<
12
{
goFmt
=
strings
.
Replace
(
goFmt
,
"h"
,
"3"
,
1
)
}
else
{
goFmt
=
strings
.
Replace
(
goFmt
,
"h"
,
"15"
,
1
)
}
goFmt
=
strings
.
Replace
(
goFmt
,
"HH"
,
"15"
,
1
)
if
val
.
Hour
()
<
12
{
if
0
<
val
.
Hour
()
&&
val
.
Hour
()
<
12
{
goFmt
=
strings
.
Replace
(
goFmt
,
"h"
,
"3"
,
1
)
goFmt
=
strings
.
Replace
(
goFmt
,
"H"
,
"3"
,
1
)
}
else
{
goFmt
=
strings
.
Replace
(
goFmt
,
"h"
,
"15"
,
1
)
goFmt
=
strings
.
Replace
(
goFmt
,
"H"
,
"15"
,
1
)
}
}
...
...
@@ -1046,7 +1047,11 @@ func parseTime(v string, format string) string {
goFmt
=
strings
.
Replace
(
goFmt
,
"[3]"
,
"3"
,
1
)
goFmt
=
strings
.
Replace
(
goFmt
,
"[15]"
,
"15"
,
1
)
}
return
val
.
Format
(
goFmt
)
s
:=
val
.
Format
(
goFmt
)
if
padding
{
s
=
strings
.
Replace
(
s
,
"00:"
,
"0:"
,
1
)
}
return
s
}
// is12HourTime checks whether an Excel time format string is a 12 hours form.
...
...
styles_test.go
浏览文件 @
c8c62c2d
...
...
@@ -293,6 +293,14 @@ func TestParseTime(t *testing.T) {
assert
.
Equal
(
t
,
"2019-03-04 05:05:42"
,
parseTime
(
"43528.2123"
,
"YYYY-MM-DD hh:mm:ss"
))
assert
.
Equal
(
t
,
"2019-03-04 05:05:42"
,
parseTime
(
"43528.2123"
,
"YYYY-MM-DD hh:mm:ss;YYYY-MM-DD hh:mm:ss"
))
assert
.
Equal
(
t
,
"3/4/2019 5:5:42"
,
parseTime
(
"43528.2123"
,
"M/D/YYYY h:m:s"
))
assert
.
Equal
(
t
,
"3/4/2019 0:5:42"
,
parseTime
(
"43528.003958333335"
,
"m/d/yyyy h:m:s"
))
assert
.
Equal
(
t
,
"3/4/2019 0:05:42"
,
parseTime
(
"43528.003958333335"
,
"M/D/YYYY h:mm:s"
))
assert
.
Equal
(
t
,
"0:05"
,
parseTime
(
"43528.003958333335"
,
"h:mm"
))
assert
.
Equal
(
t
,
"0:0"
,
parseTime
(
"6.9444444444444444E-5"
,
"h:m"
))
assert
.
Equal
(
t
,
"0:00"
,
parseTime
(
"6.9444444444444444E-5"
,
"h:mm"
))
assert
.
Equal
(
t
,
"0:0"
,
parseTime
(
"6.9444444444444444E-5"
,
"h:m"
))
assert
.
Equal
(
t
,
"12:1"
,
parseTime
(
"0.50070601851851848"
,
"h:m"
))
assert
.
Equal
(
t
,
"23:30"
,
parseTime
(
"0.97952546296296295"
,
"h:m"
))
assert
.
Equal
(
t
,
"March"
,
parseTime
(
"43528"
,
"mmmm"
))
assert
.
Equal
(
t
,
"Monday"
,
parseTime
(
"43528"
,
"dddd"
))
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录