Skip to content

Commit

Permalink
This closes qax-os#409 Remove UTC timezone requirement from date.go (q…
Browse files Browse the repository at this point in the history
…ax-os#853)

According to issue qax-os#409

There is absolutely no reason for the timezone to be in UTC, and converting the local times to UTC while keeping values is hacky at least.

Excel has no understanding of timezones, hence the user of this library should know what timezone their values are supposed to be, by following the timezone within their timeTime structs.
  • Loading branch information
Alluuu authored Jun 4, 2021
1 parent 31d88a2 commit 58f9287
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 10 deletions.
7 changes: 0 additions & 7 deletions date.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ var (
func timeToExcelTime(t time.Time) (float64, error) {
// TODO in future this should probably also handle date1904 and like TimeFromExcelTime

// Force user to explicit convet passed value to UTC time.
// Because for example 1900-01-01 00:00:00 +0300 MSK converts to 1900-01-01 00:00:00 +0230 LMT
// probably due to daylight saving.
if t.Location() != time.UTC {
return 0.0, ErrToExcelTime
}

if t.Before(excelMinTime1900) {
return 0.0, nil
}
Expand Down
2 changes: 1 addition & 1 deletion date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestTimeToExcelTime_Timezone(t *testing.T) {
for i, test := range trueExpectedDateList {
t.Run(fmt.Sprintf("TestData%d", i+1), func(t *testing.T) {
_, err := timeToExcelTime(test.GoValue.In(location))
assert.EqualError(t, err, ErrToExcelTime.Error())
assert.NoError(t, err)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion excelize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestOpenFile(t *testing.T) {

assert.NoError(t, f.SetCellValue("Sheet2", "G2", nil))

assert.EqualError(t, f.SetCellValue("Sheet2", "G4", time.Now()), ErrToExcelTime.Error())
assert.NoError(t, f.SetCellValue("Sheet2", "G4", time.Now()))

assert.NoError(t, f.SetCellValue("Sheet2", "G4", time.Now().UTC()))
// 02:46:40
Expand Down
2 changes: 1 addition & 1 deletion stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestStreamWriter(t *testing.T) {
assert.NoError(t, err)
assert.NoError(t, streamWriter.SetRow("A4", []interface{}{Cell{StyleID: styleID}, Cell{Formula: "SUM(A10,B10)"}}))
assert.NoError(t, streamWriter.SetRow("A5", []interface{}{&Cell{StyleID: styleID, Value: "cell"}, &Cell{Formula: "SUM(A10,B10)"}}))
assert.EqualError(t, streamWriter.SetRow("A6", []interface{}{time.Now()}), ErrToExcelTime.Error())
assert.NoError(t, streamWriter.SetRow("A6", []interface{}{time.Now()}))

for rowID := 10; rowID <= 51200; rowID++ {
row := make([]interface{}, 50)
Expand Down

0 comments on commit 58f9287

Please sign in to comment.