Revert "Automatically convert datetime to int64 (#1715)"
This reverts commit 8284e5defa
.
This commit is contained in:
parent
7cd51d58fa
commit
7c61c09af7
|
@ -962,26 +962,3 @@ func TestDistinctAndCols(t *testing.T) {
|
|||
assert.EqualValues(t, 1, len(names))
|
||||
assert.EqualValues(t, "test", names[0])
|
||||
}
|
||||
|
||||
func TestDateTimeInt64(t *testing.T) {
|
||||
type DateTimeInt64 struct {
|
||||
Id int64
|
||||
TimeStamp int64 `xorm:"datetime"`
|
||||
}
|
||||
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(DateTimeInt64))
|
||||
|
||||
ts := time.Now().Unix()
|
||||
cnt, err := testEngine.Insert(&DateTimeInt64{
|
||||
TimeStamp: ts,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var dts []DateTimeInt64
|
||||
err = testEngine.Find(&dts)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(dts))
|
||||
assert.EqualValues(t, ts, dts[0].TimeStamp)
|
||||
}
|
||||
|
|
|
@ -168,29 +168,7 @@ func (session *Session) bytes2Value(col *schemas.Column, fieldValue *reflect.Val
|
|||
} else if strings.EqualFold(sdata, "false") {
|
||||
x = 0
|
||||
} else {
|
||||
if col.SQLType.Name == schemas.DateTime {
|
||||
if len(sdata) == 20 {
|
||||
t, err := time.Parse("2006-01-02T15:04:05Z", sdata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("arg %v as int: %s", key, err.Error())
|
||||
}
|
||||
x = t.Unix()
|
||||
} else if len(sdata) == 19 {
|
||||
var parseFormat = "2006-01-02 15:04:05"
|
||||
if sdata[10] == 'T' {
|
||||
parseFormat = "2006-01-02T15:04:05"
|
||||
}
|
||||
t, err := time.Parse(parseFormat, sdata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("arg %v as int: %s", key, err.Error())
|
||||
}
|
||||
x = t.Unix()
|
||||
} else {
|
||||
x, err = strconv.ParseInt(sdata, 10, 64)
|
||||
}
|
||||
} else {
|
||||
x, err = strconv.ParseInt(sdata, 10, 64)
|
||||
}
|
||||
x, err = strconv.ParseInt(sdata, 10, 64)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("arg %v as int: %s", key, err.Error())
|
||||
|
|
Loading…
Reference in New Issue