[mssql] Fix save time struct's timezone

This commit is contained in:
Jinzhu 2017-08-11 17:18:49 +08:00
parent 6f64b8610d
commit 969ab67636
2 changed files with 3 additions and 3 deletions

View File

@ -79,11 +79,11 @@ func TestCreateWithExistingTimestamp(t *testing.T) {
var newUser User var newUser User
DB.First(&newUser, user.Id) 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") 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") t.Errorf("UpdatedAt should not be changed")
} }
} }

View File

@ -88,7 +88,7 @@ func (s *mssql) DataTypeOf(field *gorm.StructField) string {
} }
case reflect.Struct: case reflect.Struct:
if _, ok := dataValue.Interface().(time.Time); ok { if _, ok := dataValue.Interface().(time.Time); ok {
sqlType = "datetime2" sqlType = "datetimeoffset"
} }
default: default:
if gorm.IsByteArrayOrSlice(dataValue) { if gorm.IsByteArrayOrSlice(dataValue) {