Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
This closes #2512, number format keeps milliseconds for date and time…
… values
  • Loading branch information
ruziba3vich committed Nov 20, 2026
commit 1474db763c652d2dba6a2ef003014a489e09d8e2
3 changes: 3 additions & 0 deletions numfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5630,6 +5630,9 @@ func (nf *numberFormat) dateTimeHandler() string {
nf.t, nf.hours, nf.seconds = timeFromExcelTime(nf.number, nf.date1904), false, false
if !nf.useMillisecond {
nf.t = nf.t.Add(time.Duration(math.Round(float64(nf.t.Nanosecond())/1e9)) * time.Second)
} else if days := math.Floor(nf.number); days > 61 {
// The timeFromExcelTime function rounds these dates to whole seconds.
nf.t = timeFromExcelTime(days, nf.date1904).Add(time.Duration(nanosInADay * (nf.number - days)).Round(time.Millisecond))
}
for i, token := range nf.section[nf.sectionIdx].Items {
if token.TType == nfp.TokenTypeCurrencyLanguage {
Expand Down
5 changes: 5 additions & 0 deletions numfmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4255,6 +4255,11 @@ func TestNumFmt(t *testing.T) {
{"0.007", "[h]:mm:ss.0", "0:10:04.8"},
{"0.007", "[h]:mm:ss.00", "0:10:04.80"},
{"0.007", "[h]:mm:ss.000", "0:10:04.800"},
{"0.5000058", "hh:mm:ss.000", "12:00:00.501"},
{"44197.5000058", "hh:mm:ss.000", "12:00:00.501"},
{"44197.5000058", "yyyy-mm-dd hh:mm:ss.00", "2021-01-01 12:00:00.50"},
{"44197.123456789", "mm:ss.000", "57:46.667"},
{"44197.99999999", "yyyy-mm-dd hh:mm:ss.000", "2021-01-01 23:59:59.999"},
{"0.007", "[h]:mm:ss.0000", "0:10:04.800"},
{"0.3270833333", "[h]:mm", "7:51"},
{"0.5347222222", "[h]:mm", "12:50"},
Expand Down
Loading