|
|
@@ -500,3 +500,51 @@ func (s *CellSuite) TestSetValue(c *C) {
|
|
|
cell.SetValue([]string{"test"})
|
|
|
c.Assert(cell.Value, Equals, "[test]")
|
|
|
}
|
|
|
+
|
|
|
+func (s *CellSuite) TestSetDateWithOptions(c *C) {
|
|
|
+ cell := Cell{}
|
|
|
+
|
|
|
+ // time
|
|
|
+ cell.SetDate(time.Unix(0, 0))
|
|
|
+ val, err := cell.Float()
|
|
|
+ c.Assert(err, IsNil)
|
|
|
+ c.Assert(math.Floor(val), Equals, 25569.0)
|
|
|
+
|
|
|
+ // get a specific time's float value, that isn't near zero, to compare against
|
|
|
+ date2016UTC := time.Date(2016, 1, 1, 12, 0, 0, 0, time.UTC)
|
|
|
+ cell.SetDate(date2016UTC)
|
|
|
+ utcVal, err := cell.Float()
|
|
|
+ c.Assert(err, IsNil)
|
|
|
+
|
|
|
+ // test ny timezone
|
|
|
+ nyTZ, err := time.LoadLocation("America/New_York")
|
|
|
+ c.Assert(err, IsNil)
|
|
|
+ date2016NY := time.Date(2016, 1, 1, 12, 0, 0, 0, nyTZ)
|
|
|
+ cell.SetDateWithOptions(date2016UTC, DateTimeOptions{
|
|
|
+ ExcelTimeFormat: "test_format1",
|
|
|
+ Location: nyTZ,
|
|
|
+ })
|
|
|
+ val, err = cell.Float()
|
|
|
+ c.Assert(err, IsNil)
|
|
|
+ _, offset := date2016NY.Zone()
|
|
|
+
|
|
|
+ // the difference in our values (utc and ny) should equal the offset represented as fraction of a day
|
|
|
+ c.Assert(val-utcVal-float64(offset)/86400.0 < 0.00000001, Equals, true)
|
|
|
+
|
|
|
+ // test jp timezone
|
|
|
+ jpTZ, err := time.LoadLocation("Asia/Tokyo")
|
|
|
+ c.Assert(err, IsNil)
|
|
|
+ date2016JP := time.Date(2016, 1, 1, 12, 0, 0, 0, jpTZ)
|
|
|
+
|
|
|
+ cell.SetDateWithOptions(date2016UTC, DateTimeOptions{
|
|
|
+ ExcelTimeFormat: "test_format2",
|
|
|
+ Location: jpTZ,
|
|
|
+ })
|
|
|
+ val, err = cell.Float()
|
|
|
+ c.Assert(err, IsNil)
|
|
|
+ _, offset = date2016JP.Zone()
|
|
|
+
|
|
|
+ // the difference in our values (utc and ny) should equal the offset represented as fraction of a day
|
|
|
+ c.Assert(val-utcVal-float64(offset)/86400.0 < 0.00000001, Equals, true)
|
|
|
+
|
|
|
+}
|