parent
4f47737d64
commit
6ced438f39
@ -1,42 +1,42 @@
|
|||||||
package excelize
|
package excelize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type dateTest struct {
|
type dateTest struct {
|
||||||
ExcelValue float64
|
ExcelValue float64
|
||||||
GoValue time.Time
|
GoValue time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimeToExcelTime(t *testing.T) {
|
func TestTimeToExcelTime(t *testing.T) {
|
||||||
trueExpectedInputList := []dateTest {
|
trueExpectedInputList := []dateTest{
|
||||||
{0.0, time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC)},
|
{0.0, time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC)},
|
||||||
{25569.0, time.Unix(0, 0)},
|
{25569.0, time.Unix(0, 0)},
|
||||||
{43269.0, time.Date(2018, 6, 18, 0, 0, 0, 0, time.UTC)},
|
{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)},
|
{401769.0, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range trueExpectedInputList {
|
for _, test := range trueExpectedInputList {
|
||||||
if test.ExcelValue != timeToExcelTime(test.GoValue) {
|
if test.ExcelValue != timeToExcelTime(test.GoValue) {
|
||||||
t.Fatalf("Expected %v from %v = true, got %v\n", test.ExcelValue, test.GoValue, 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) {
|
func TestTimeFromExcelTime(t *testing.T) {
|
||||||
trueExpectedInputList := []dateTest {
|
trueExpectedInputList := []dateTest{
|
||||||
{0.0, time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC)},
|
{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)},
|
{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)},
|
{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)},
|
{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)},
|
{401769.0, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range trueExpectedInputList {
|
for _, test := range trueExpectedInputList {
|
||||||
if test.GoValue != timeFromExcelTime(test.ExcelValue, false) {
|
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))
|
t.Fatalf("Expected %v from %v = true, got %v\n", test.GoValue, test.ExcelValue, timeFromExcelTime(test.ExcelValue, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue