Skip to content

Commit 2e9c290

Browse files
committed
This closes qax-os#1587, fix incorrect date time format result
1 parent 7f3d663 commit 2e9c290

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

numfmt.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1855,15 +1855,15 @@ func (nf *numberFormat) secondsHandler(token nfp.Token) {
18551855
// for a number format expression.
18561856
func (nf *numberFormat) elapsedDateTimesHandler(token nfp.Token) {
18571857
if strings.Contains(strings.ToUpper(token.TValue), "H") {
1858-
nf.result += fmt.Sprintf("%.f", nf.t.Sub(excel1900Epoc).Hours())
1858+
nf.result += fmt.Sprintf("%.f", math.Floor(nf.t.Sub(excel1900Epoc).Hours()))
18591859
return
18601860
}
18611861
if strings.Contains(strings.ToUpper(token.TValue), "M") {
1862-
nf.result += fmt.Sprintf("%.f", nf.t.Sub(excel1900Epoc).Minutes())
1862+
nf.result += fmt.Sprintf("%.f", math.Floor(nf.t.Sub(excel1900Epoc).Minutes()))
18631863
return
18641864
}
18651865
if strings.Contains(strings.ToUpper(token.TValue), "S") {
1866-
nf.result += fmt.Sprintf("%.f", nf.t.Sub(excel1900Epoc).Seconds())
1866+
nf.result += fmt.Sprintf("%.f", math.Floor(nf.t.Sub(excel1900Epoc).Seconds()))
18671867
return
18681868
}
18691869
}

numfmt_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestNumFmt(t *testing.T) {
4848
{"43543.086539351854", "hh:mm:ss AM/PM", "02:04:37 AM"},
4949
{"43543.086539351854", "AM/PM hh:mm:ss", "AM 02:04:37"},
5050
{"43543.086539351854", "AM/PM hh:mm:ss a/p", "AM 02:04:37 a"},
51+
{"0.609375", "[HH]:mm:ss", "14:37:30"},
5152
{"43528", "YYYY", "2019"},
5253
{"43528", "", "43528"},
5354
{"43528.2123", "YYYY-MM-DD hh:mm:ss", "2019-03-04 05:05:43"},

0 commit comments

Comments
 (0)