diff options
author | xuri <xuri.me@gmail.com> | 2020-05-22 16:53:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 16:53:46 +0800 |
commit | ec14de32f0c06f7a26b6b79578f666c0cc50b72c (patch) | |
tree | c6ebd61a7d9a7da5b993ffb82e4fb6c036e75d6a /date_test.go | |
parent | aa7eadbffe6ae2f9f86201bbaaa4c1d1e8829cae (diff) | |
parent | 2efc7107ff30dc7f1e1a798082616ee488f99489 (diff) |
Merge branch 'master' into fix/cell_lock
Diffstat (limited to 'date_test.go')
-rw-r--r-- | date_test.go | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/date_test.go b/date_test.go index 2885af0..ee01356 100644 --- a/date_test.go +++ b/date_test.go @@ -28,6 +28,14 @@ var trueExpectedDateList = []dateTest{ {401769.00000000000, time.Date(3000, time.January, 1, 0, 0, 0, 0, time.UTC)}, } +var excelTimeInputList = []dateTest{ + {0.0, time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC)}, + {60.0, time.Date(1900, 2, 28, 0, 0, 0, 0, time.UTC)}, + {61.0, time.Date(1900, 3, 1, 0, 0, 0, 0, time.UTC)}, + {41275.0, time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC)}, + {401769.0, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)}, +} + func TestTimeToExcelTime(t *testing.T) { for i, test := range trueExpectedDateList { t.Run(fmt.Sprintf("TestData%d", i+1), func(t *testing.T) { @@ -53,15 +61,7 @@ func TestTimeToExcelTime_Timezone(t *testing.T) { } func TestTimeFromExcelTime(t *testing.T) { - trueExpectedInputList := []dateTest{ - {0.0, time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC)}, - {60.0, time.Date(1900, 2, 28, 0, 0, 0, 0, time.UTC)}, - {61.0, time.Date(1900, 3, 1, 0, 0, 0, 0, time.UTC)}, - {41275.0, time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC)}, - {401769.0, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)}, - } - - for i, test := range trueExpectedInputList { + for i, test := range excelTimeInputList { t.Run(fmt.Sprintf("TestData%d", i+1), func(t *testing.T) { assert.Equal(t, test.GoValue, timeFromExcelTime(test.ExcelValue, false)) }) @@ -73,3 +73,17 @@ func TestTimeFromExcelTime_1904(t *testing.T) { timeFromExcelTime(61, true) timeFromExcelTime(62, true) } + +func TestExcelDateToTime(t *testing.T) { + // Check normal case + for i, test := range excelTimeInputList { + t.Run(fmt.Sprintf("TestData%d", i+1), func(t *testing.T) { + timeValue, err := ExcelDateToTime(test.ExcelValue, false) + assert.Equal(t, test.GoValue, timeValue) + assert.NoError(t, err) + }) + } + // Check error case + _, err := ExcelDateToTime(-1, false) + assert.EqualError(t, err, "invalid date value -1.000000, negative values are not supported supported") +} |