From 969ab67636595992dab7b6ffbd4ede21b67d1b5b Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 11 Aug 2017 17:18:49 +0800 Subject: [PATCH] [mssql] Fix save time struct's timezone --- create_test.go | 4 ++-- dialects/mssql/mssql.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/create_test.go b/create_test.go index 9e17ae94..38d75af8 100644 --- a/create_test.go +++ b/create_test.go @@ -79,11 +79,11 @@ func TestCreateWithExistingTimestamp(t *testing.T) { var newUser User DB.First(&newUser, user.Id) - if newUser.CreatedAt.Format(time.RFC3339) != timeA.Format(time.RFC3339) { + if newUser.CreatedAt.UTC().Format(time.RFC3339) != timeA.UTC().Format(time.RFC3339) { t.Errorf("CreatedAt should not be changed") } - if newUser.UpdatedAt.Format(time.RFC3339) != timeA.Format(time.RFC3339) { + if newUser.UpdatedAt.UTC().Format(time.RFC3339) != timeA.UTC().Format(time.RFC3339) { t.Errorf("UpdatedAt should not be changed") } } diff --git a/dialects/mssql/mssql.go b/dialects/mssql/mssql.go index 46b5ec9c..de2ae7ca 100644 --- a/dialects/mssql/mssql.go +++ b/dialects/mssql/mssql.go @@ -88,7 +88,7 @@ func (s *mssql) DataTypeOf(field *gorm.StructField) string { } case reflect.Struct: if _, ok := dataValue.Interface().(time.Time); ok { - sqlType = "datetime2" + sqlType = "datetimeoffset" } default: if gorm.IsByteArrayOrSlice(dataValue) {