From a9c19835c990bbc9f1daabd204c4a102ccafc263 Mon Sep 17 00:00:00 2001 From: qiuyesuifeng Date: Tue, 8 Sep 2015 16:58:43 +0800 Subject: [PATCH] mysqldef: fix TestCodec location bug. fix issue #68. --- mysqldef/time_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mysqldef/time_test.go b/mysqldef/time_test.go index 57d1a10df7..f7964e47eb 100644 --- a/mysqldef/time_test.go +++ b/mysqldef/time_test.go @@ -289,6 +289,26 @@ func (s *testTimeSuite) TestYear(c *C) { } +func (s *testTimeSuite) getLocation(c *C) *time.Location { + locations := []string{"Asia/Shanghai", "Europe/Berlin"} + timeFormat := "Jan 2, 2006 at 3:04pm (MST)" + + z, err := time.LoadLocation(locations[0]) + c.Assert(err, IsNil) + + t1, err := time.ParseInLocation(timeFormat, "Jul 9, 2012 at 5:02am (CEST)", z) + c.Assert(err, IsNil) + t2, err := time.Parse(timeFormat, "Jul 9, 2012 at 5:02am (CEST)") + c.Assert(err, IsNil) + + if t1.Equal(t2) { + z, err = time.LoadLocation(locations[1]) + c.Assert(err, IsNil) + } + + return z +} + func (s *testTimeSuite) TestCodec(c *C) { t, err := ParseTimestamp("2010-10-10 10:11:11") c.Assert(err, IsNil) @@ -298,7 +318,7 @@ func (s *testTimeSuite) TestCodec(c *C) { var t1 Time t1.Type = TypeTimestamp - z, _ := time.LoadLocation("Europe/Berlin") + z := s.getLocation(c) err = t1.UnmarshalInLocation(b, z) c.Assert(err, IsNil)