fix TestTagTime

This commit is contained in:
CyJaySong 2023-07-14 18:27:29 +08:00
parent a6b31d79d7
commit 50ef83d456
2 changed files with 13 additions and 5 deletions

View File

@ -69,6 +69,13 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
} }
dt = dt.In(convertedLocation) dt = dt.In(convertedLocation)
return &dt, nil 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] == '-' { } else if len(s) == 10 && s[4] == '-' {
if s == "0000-00-00" || s == "0001-01-01" { if s == "0000-00-00" || s == "0001-01-01" {
return &time.Time{}, nil return &time.Time{}, nil

View File

@ -6,12 +6,11 @@ package integrations
import ( import (
"fmt" "fmt"
"github.com/stretchr/testify/assert"
"sort" "sort"
"strings"
"testing" "testing"
"time" "time"
"xorm.io/xorm/convert"
"github.com/stretchr/testify/assert"
"xorm.io/xorm/internal/utils" "xorm.io/xorm/internal/utils"
"xorm.io/xorm/names" "xorm.io/xorm/names"
"xorm.io/xorm/schemas" "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) has, err = testEngine.Table("tag_u_t_c_struct").Cols("created").Get(&tm)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, has) 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) { func TestTagAutoIncr(t *testing.T) {