diff --git a/.gitignore b/.gitignore index f1757b983..3629e49ac 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ # Folders _obj _test +vendor/ # Architecture specific extensions/prefixes *.[568vq] diff --git a/engine.go b/engine.go index ebcab91bc..0d1abb803 100644 --- a/engine.go +++ b/engine.go @@ -1586,7 +1586,7 @@ func (engine *Engine) formatTime(sqlTypeName string, t time.Time) (v interface{} v = s[11:19] case core.Date: v = t.Format("2006-01-02") - case core.DateTime, core.TimeStamp: + case core.DateTime, core.TimeStamp, core.Varchar: // !DarthPestilane! format time when sqlTypeName is core.Varchar. v = t.Format("2006-01-02 15:04:05") case core.TimeStampz: if engine.dialect.DBType() == core.MSSQL { diff --git a/time_test.go b/time_test.go index b7e4d12b2..9a8219831 100644 --- a/time_test.go +++ b/time_test.go @@ -255,10 +255,12 @@ func TestTimeUserDeleted(t *testing.T) { assert.NoError(t, prepareEngine()) type UserDeleted struct { - Id string - CreatedAt time.Time `xorm:"created"` - UpdatedAt time.Time `xorm:"updated"` - DeletedAt time.Time `xorm:"deleted"` + Id string + CreatedAt time.Time `xorm:"created"` + UpdatedAt time.Time `xorm:"updated"` + DeletedAt time.Time `xorm:"deleted"` + CreatedAtStr string `xorm:"datetime created"` + UpdatedAtStr string `xorm:"datetime updated"` } assertSync(t, new(UserDeleted)) @@ -282,6 +284,7 @@ func TestTimeUserDeleted(t *testing.T) { assert.EqualValues(t, formatTime(user.UpdatedAt), formatTime(user2.UpdatedAt)) assert.True(t, isTimeZero(user2.DeletedAt)) fmt.Println("user2", user2.CreatedAt, user2.UpdatedAt, user2.DeletedAt) + fmt.Println("user2 str", user2.CreatedAtStr, user2.UpdatedAtStr) var user3 UserDeleted cnt, err = testEngine.Where("id = ?", "lunny").Delete(&user3)