Skip to content

Commit

Permalink
This closes #1587, fix incorrect date time format result
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Jul 26, 2023
1 parent 7f3d663 commit 2e9c290
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions numfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1855,15 +1855,15 @@ func (nf *numberFormat) secondsHandler(token nfp.Token) {
// for a number format expression.
func (nf *numberFormat) elapsedDateTimesHandler(token nfp.Token) {
if strings.Contains(strings.ToUpper(token.TValue), "H") {
nf.result += fmt.Sprintf("%.f", nf.t.Sub(excel1900Epoc).Hours())
nf.result += fmt.Sprintf("%.f", math.Floor(nf.t.Sub(excel1900Epoc).Hours()))
return
}
if strings.Contains(strings.ToUpper(token.TValue), "M") {
nf.result += fmt.Sprintf("%.f", nf.t.Sub(excel1900Epoc).Minutes())
nf.result += fmt.Sprintf("%.f", math.Floor(nf.t.Sub(excel1900Epoc).Minutes()))
return
}
if strings.Contains(strings.ToUpper(token.TValue), "S") {
nf.result += fmt.Sprintf("%.f", nf.t.Sub(excel1900Epoc).Seconds())
nf.result += fmt.Sprintf("%.f", math.Floor(nf.t.Sub(excel1900Epoc).Seconds()))
return
}
}
Expand Down
1 change: 1 addition & 0 deletions numfmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestNumFmt(t *testing.T) {
{"43543.086539351854", "hh:mm:ss AM/PM", "02:04:37 AM"},
{"43543.086539351854", "AM/PM hh:mm:ss", "AM 02:04:37"},
{"43543.086539351854", "AM/PM hh:mm:ss a/p", "AM 02:04:37 a"},
{"0.609375", "[HH]:mm:ss", "14:37:30"},
{"43528", "YYYY", "2019"},
{"43528", "", "43528"},
{"43528.2123", "YYYY-MM-DD hh:mm:ss", "2019-03-04 05:05:43"},
Expand Down

0 comments on commit 2e9c290

Please sign in to comment.