summaryrefslogtreecommitdiff
path: root/date_test.go
diff options
context:
space:
mode:
authorMārtiņš <liepumartins@users.noreply.github.com>2018-06-19 15:28:40 +0300
committerlietotajs <liepumartins@users.noreply.github.com>2018-06-20 09:16:25 +0300
commit37c470e8c0df99bd47f7054834e0db93b75ab073 (patch)
tree1e4a44eac7de7295b5de48bab75aea254a1b7ef4 /date_test.go
parent5db716d849d51b630822571c8a0aa4edd7cc8365 (diff)
Ability to parse dates further in future
Golangs time.Duration uses nanoseconds, thus it is limited to approximately 290 years.
Diffstat (limited to 'date_test.go')
-rw-r--r--date_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/date_test.go b/date_test.go
new file mode 100644
index 0000000..bf071e0
--- /dev/null
+++ b/date_test.go
@@ -0,0 +1,42 @@
+package excelize
+
+import (
+ "testing"
+ "time"
+)
+
+type dateTest struct {
+ ExcelValue float64
+ GoValue time.Time
+}
+
+func TestTimeToExcelTime(t *testing.T) {
+ trueExpectedInputList := []dateTest {
+ {0.0, time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC)},
+ {25569.0, time.Unix(0, 0)},
+ {43269.0, time.Date(2018, 6, 18, 0, 0, 0, 0, time.UTC)},
+ {401769.0, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)},
+ }
+
+ for _, test := range trueExpectedInputList {
+ if test.ExcelValue != timeToExcelTime(test.GoValue) {
+ t.Fatalf("Expected %v from %v = true, got %v\n", test.ExcelValue, test.GoValue, timeToExcelTime(test.GoValue))
+ }
+ }
+}
+
+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 _, test := range trueExpectedInputList {
+ if test.GoValue != timeFromExcelTime(test.ExcelValue, false) {
+ t.Fatalf("Expected %v from %v = true, got %v\n", test.GoValue, test.ExcelValue, timeFromExcelTime(test.ExcelValue, false))
+ }
+ }
+}