Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

format time when sqlTypeName is core.Varchar #1026

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Folders
_obj
_test
vendor/

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
2 changes: 1 addition & 1 deletion engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down