diff options
author | xuri <xuri.me@gmail.com> | 2021-10-12 00:01:11 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-10-12 00:01:11 +0800 |
commit | 58fd279dc845ebd9ccd4ba336d7c664824e70e43 (patch) | |
tree | dc0954191e49981afff1e260a66cacb2067c5e67 /date.go | |
parent | aa8f6f02bdf933df6cffec6b408276d02ed9e6b0 (diff) |
This closes #1030, fix date rounding error
Diffstat (limited to 'date.go')
-rw-r--r-- | date.go | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -20,6 +20,7 @@ const ( nanosInADay = float64((24 * time.Hour) / time.Nanosecond) dayNanoseconds = 24 * time.Hour maxDuration = 290 * 364 * dayNanoseconds + roundEpsilon = 1e-9 ) var ( @@ -151,14 +152,14 @@ func timeFromExcelTime(excelTime float64, date1904 bool) time.Time { } return date } - var floatPart = excelTime - float64(wholeDaysPart) + var floatPart = excelTime - float64(wholeDaysPart) + roundEpsilon if date1904 { date = excel1904Epoc } else { date = excel1900Epoc } durationPart := time.Duration(nanosInADay * floatPart) - return date.AddDate(0, 0, wholeDaysPart).Add(durationPart) + return date.AddDate(0, 0, wholeDaysPart).Add(durationPart).Truncate(time.Second) } // ExcelDateToTime converts a float-based excel date representation to a time.Time. |