From 58fd279dc845ebd9ccd4ba336d7c664824e70e43 Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 12 Oct 2021 00:01:11 +0800 Subject: This closes #1030, fix date rounding error --- date.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'date.go') diff --git a/date.go b/date.go index b8c26e0..c4acd6d 100644 --- a/date.go +++ b/date.go @@ -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. -- cgit v1.2.1