-
Notifications
You must be signed in to change notification settings - Fork 21
/
date_test.go
47 lines (39 loc) · 991 Bytes
/
date_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package xlsxreader
import (
"testing"
"github.com/stretchr/testify/require"
)
var excelDateTests = []struct {
input string
expected string
}{
{"43489", "2019-01-24"},
{"43489.0", "2019-01-24"},
{"-100", "1899-09-21"},
{"-100.0", "1899-09-21"},
{"43489.25", "2019-01-24T06:00:00Z"},
{"43489.5", "2019-01-24T12:00:00Z"},
{"43489.99999", "2019-01-24T23:59:59Z"},
{"-100.25", "1899-09-20T18:00:00Z"},
}
func TestConvertingValidExcelDates(t *testing.T) {
for _, test := range excelDateTests {
t.Run("ValidExcel-"+test.input, func(t *testing.T) {
actual, err := convertExcelDateToDateString(test.input)
require.NoError(t, err)
require.Equal(t, test.expected, actual)
})
}
}
var invalidDateTests = []string{
"wat",
"100.25.25",
}
func TestConvertingInvalidExcelDates(t *testing.T) {
for _, test := range invalidDateTests {
t.Run("InvalidExcel-"+test, func(t *testing.T) {
_, err := convertExcelDateToDateString(test)
require.Error(t, err)
})
}
}