summaryrefslogtreecommitdiff
path: root/date.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2021-10-12 00:01:11 +0800
committerxuri <xuri.me@gmail.com>2021-10-12 00:01:11 +0800
commit58fd279dc845ebd9ccd4ba336d7c664824e70e43 (patch)
treedc0954191e49981afff1e260a66cacb2067c5e67 /date.go
parentaa8f6f02bdf933df6cffec6b408276d02ed9e6b0 (diff)
This closes #1030, fix date rounding error
Diffstat (limited to 'date.go')
-rw-r--r--date.go5
1 files changed, 3 insertions, 2 deletions
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.