From 7bbf71fb29aea449284f42d0c29f13198a484079 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 15 Mar 2014 10:17:43 +0800 Subject: [PATCH] Add tests to make sure time with zone won't be changed after save --- main_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/main_test.go b/main_test.go index dc60de24..65caf58d 100644 --- a/main_test.go +++ b/main_test.go @@ -1702,6 +1702,36 @@ func TestExecRawSql(t *testing.T) { } } +func TestTimeWithZone(t *testing.T) { + var format = "2006-01-02 15:04:05 -0700" + var times []time.Time + GMT8, _ := time.LoadLocation("Asia/Shanghai") + times = append(times, time.Date(2013, 02, 19, 1, 51, 49, 123456789, GMT8)) + times = append(times, time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.UTC)) + + for _, vtime := range times { + user := User{Name: "time_with_zone", Birthday: vtime} + db.Save(&user) + if user.Birthday.UTC().Format(format) != "2013-02-18 17:51:49 +0000" { + t.Errorf("User's birthday should not be changed after save") + } + + if user.DeletedAt.UTC().Format(format) != "0001-01-01 00:00:00 +0000" { + t.Errorf("User's deleted at should be zero") + } + + var findUser User + db.First(&findUser, "name = ?", "time_with_zone") + if findUser.Birthday.UTC().Format(format) != "2013-02-18 17:51:49 +0000" { + t.Errorf("User's birthday should not be changed after find") + } + + if findUser.DeletedAt.UTC().Format(format) != "0001-01-01 00:00:00 +0000" { + t.Errorf("User's deleted at should be zero") + } + } +} + func BenchmarkGorm(b *testing.B) { b.N = 2000 for x := 0; x < b.N; x++ {