Merge pull request #4372 from a631807682/fix/develop/parse-time

fix(orm/orm_raw): missing type time parse
This commit is contained in:
Ming Deng 2020-12-19 21:08:40 +08:00 committed by GitHub
commit a559f6c505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -181,6 +181,12 @@ func (o *rawSet) setFieldValue(ind reflect.Value, value interface{}) {
if err == nil {
ind.Set(reflect.ValueOf(t))
}
} else if len(str) >= 8 {
str = str[:8]
t, err := time.ParseInLocation(formatTime, str, DefaultTimeLoc)
if err == nil {
ind.Set(reflect.ValueOf(t))
}
}
}
case sql.NullString, sql.NullInt64, sql.NullFloat64, sql.NullBool:

View File

@ -1746,6 +1746,10 @@ func TestRawQueryRow(t *testing.T) {
throwFail(t, AssertIs(id, 1))
break
case "time":
v = v.(time.Time).In(DefaultTimeLoc)
value := dataValues[col].(time.Time).In(DefaultTimeLoc)
assert.True(t, v.(time.Time).Sub(value) <= time.Second)
break
case "date":
case "datetime":
v = v.(time.Time).In(DefaultTimeLoc)