diff options
author | xuri <xuri.me@gmail.com> | 2022-05-02 12:30:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 12:30:18 +0800 |
commit | eed431e0fc2f61b13e7745857a41cb47d9f7f810 (patch) | |
tree | 8244e1b4749d177313e51a3d73686d16c0176451 /date.go | |
parent | 773d4afa32a55349a7b178c4c76d182f9ed0221f (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.go | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -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 |