From 50ef83d4567363aa728fce60f6fb5d08ba457031 Mon Sep 17 00:00:00 2001 From: CyJaySong Date: Fri, 14 Jul 2023 18:27:29 +0800 Subject: [PATCH] fix TestTagTime --- convert/time.go | 7 +++++++ integrations/tags_test.go | 11 ++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/convert/time.go b/convert/time.go index 544eca6f..6e20b510 100644 --- a/convert/time.go +++ b/convert/time.go @@ -69,6 +69,13 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t } dt = dt.In(convertedLocation) return &dt, nil + } else if len(s) == 21 && s[10] == 'T' { + dt, err := time.ParseInLocation("2006-01-02T15:04:05", s[:19], originalLocation) + if err != nil { + return nil, err + } + dt = dt.In(convertedLocation) + return &dt, nil } else if len(s) == 10 && s[4] == '-' { if s == "0000-00-00" || s == "0001-01-01" { return &time.Time{}, nil diff --git a/integrations/tags_test.go b/integrations/tags_test.go index 4c33d56c..bf021058 100644 --- a/integrations/tags_test.go +++ b/integrations/tags_test.go @@ -6,12 +6,11 @@ package integrations import ( "fmt" + "github.com/stretchr/testify/assert" "sort" - "strings" "testing" "time" - - "github.com/stretchr/testify/assert" + "xorm.io/xorm/convert" "xorm.io/xorm/internal/utils" "xorm.io/xorm/names" "xorm.io/xorm/schemas" @@ -1201,8 +1200,10 @@ func TestTagTime(t *testing.T) { has, err = testEngine.Table("tag_u_t_c_struct").Cols("created").Get(&tm) assert.NoError(t, err) assert.True(t, has) - assert.EqualValues(t, s.Created.UTC().Format("2006-01-02 15:04:05"), - strings.ReplaceAll(strings.ReplaceAll(tm, "T", " "), "Z", "")) + + tmTime, err := convert.String2Time(tm, time.UTC, time.UTC) + assert.NoError(t, err) + assert.EqualValues(t, s.Created.UTC().Format("2006-01-02 15:04:05"), tmTime.Format("2006-01-02 15:04:05")) } func TestTagAutoIncr(t *testing.T) {