summaryrefslogtreecommitdiff
path: root/date.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2022-05-02 12:30:18 +0800
committerGitHub <noreply@github.com>2022-05-02 12:30:18 +0800
commiteed431e0fc2f61b13e7745857a41cb47d9f7f810 (patch)
tree8244e1b4749d177313e51a3d73686d16c0176451 /date.go
parent773d4afa32a55349a7b178c4c76d182f9ed0221f (diff)
This closes #1219, fixes cell value reading issue, improves performance, and 1904 date system support
- Fix incorrect cell data types casting results when number formatting - Support set cell value on 1904 date system enabled, ref #1212 - Improve performance for set sheet row and the merging cells, fix performance impact when resolving #1129
Diffstat (limited to 'date.go')
-rw-r--r--date.go20
1 files changed, 9 insertions, 11 deletions
diff --git a/date.go b/date.go
index 1574af7..3e81319 100644
--- a/date.go
+++ b/date.go
@@ -32,21 +32,19 @@ var (
)
// timeToExcelTime provides a function to convert time to Excel time.
-func timeToExcelTime(t time.Time) (float64, error) {
- // TODO in future this should probably also handle date1904 and like TimeFromExcelTime
-
- if t.Before(excelMinTime1900) {
+func timeToExcelTime(t time.Time, date1904 bool) (float64, error) {
+ date := excelMinTime1900
+ if date1904 {
+ date = excel1904Epoc
+ }
+ if t.Before(date) {
return 0, nil
}
-
- tt := t
- diff := t.Sub(excelMinTime1900)
- result := float64(0)
-
+ tt, diff, result := t, t.Sub(date), 0.0
for diff >= maxDuration {
result += float64(maxDuration / dayNanoseconds)
tt = tt.Add(-maxDuration)
- diff = tt.Sub(excelMinTime1900)
+ diff = tt.Sub(date)
}
rem := diff % dayNanoseconds
@@ -57,7 +55,7 @@ func timeToExcelTime(t time.Time) (float64, error) {
// Microsoft intentionally included this bug in Excel so that it would remain compatible with the spreadsheet
// program that had the majority market share at the time; Lotus 1-2-3.
// https://www.myonlinetraininghub.com/excel-date-and-time
- if t.After(excelBuggyPeriodStart) {
+ if !date1904 && t.After(excelBuggyPeriodStart) {
result++
}
return result, nil