@@ -28,6 +28,14 @@ var trueExpectedDateList = []dateTest{
28
28
{401769.00000000000 , time .Date (3000 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC )},
29
29
}
30
30
31
+ var excelTimeInputList = []dateTest {
32
+ {0.0 , time .Date (1899 , 12 , 30 , 0 , 0 , 0 , 0 , time .UTC )},
33
+ {60.0 , time .Date (1900 , 2 , 28 , 0 , 0 , 0 , 0 , time .UTC )},
34
+ {61.0 , time .Date (1900 , 3 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
35
+ {41275.0 , time .Date (2013 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
36
+ {401769.0 , time .Date (3000 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
37
+ }
38
+
31
39
func TestTimeToExcelTime (t * testing.T ) {
32
40
for i , test := range trueExpectedDateList {
33
41
t .Run (fmt .Sprintf ("TestData%d" , i + 1 ), func (t * testing.T ) {
@@ -53,15 +61,7 @@ func TestTimeToExcelTime_Timezone(t *testing.T) {
53
61
}
54
62
55
63
func TestTimeFromExcelTime (t * testing.T ) {
56
- trueExpectedInputList := []dateTest {
57
- {0.0 , time .Date (1899 , 12 , 30 , 0 , 0 , 0 , 0 , time .UTC )},
58
- {60.0 , time .Date (1900 , 2 , 28 , 0 , 0 , 0 , 0 , time .UTC )},
59
- {61.0 , time .Date (1900 , 3 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
60
- {41275.0 , time .Date (2013 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
61
- {401769.0 , time .Date (3000 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
62
- }
63
-
64
- for i , test := range trueExpectedInputList {
64
+ for i , test := range excelTimeInputList {
65
65
t .Run (fmt .Sprintf ("TestData%d" , i + 1 ), func (t * testing.T ) {
66
66
assert .Equal (t , test .GoValue , timeFromExcelTime (test .ExcelValue , false ))
67
67
})
@@ -73,3 +73,17 @@ func TestTimeFromExcelTime_1904(t *testing.T) {
73
73
timeFromExcelTime (61 , true )
74
74
timeFromExcelTime (62 , true )
75
75
}
76
+
77
+ func TestExcelDateToTime (t * testing.T ) {
78
+ // Check normal case
79
+ for i , test := range excelTimeInputList {
80
+ t .Run (fmt .Sprintf ("TestData%d" , i + 1 ), func (t * testing.T ) {
81
+ timeValue , err := ExcelDateToTime (test .ExcelValue , false )
82
+ assert .Equal (t , test .GoValue , timeValue )
83
+ assert .NoError (t , err )
84
+ })
85
+ }
86
+ // Check error case
87
+ _ , err := ExcelDateToTime (- 1 , false )
88
+ assert .EqualError (t , err , "invalid date value -1.000000, negative values are not supported supported" )
89
+ }
0 commit comments