Merge pull request #431 from deepilla/issue-430

Don't convert Unix times to nanoseconds when querying datetime fields…
This commit is contained in:
mattn 2017-07-01 20:48:21 +09:00 committed by GitHub
commit 8a4c825cfc
2 changed files with 4 additions and 2 deletions

View File

@ -961,10 +961,11 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
// large to be a reasonable timestamp in seconds. // large to be a reasonable timestamp in seconds.
if val > 1e12 || val < -1e12 { if val > 1e12 || val < -1e12 {
val *= int64(time.Millisecond) // convert ms to nsec val *= int64(time.Millisecond) // convert ms to nsec
t = time.Unix(0, val)
} else { } else {
val *= int64(time.Second) // convert sec to nsec t = time.Unix(val, 0)
} }
t = time.Unix(0, val).UTC() t = t.UTC()
if rc.s.c.loc != nil { if rc.s.c.loc != nil {
t = t.In(rc.s.c.loc) t = t.In(rc.s.c.loc)
} }

View File

@ -403,6 +403,7 @@ func TestTimestamp(t *testing.T) {
}{ }{
{"nonsense", time.Time{}}, {"nonsense", time.Time{}},
{"0000-00-00 00:00:00", time.Time{}}, {"0000-00-00 00:00:00", time.Time{}},
{time.Time{}.Unix(), time.Time{}},
{timestamp1, timestamp1}, {timestamp1, timestamp1},
{timestamp2.Unix(), timestamp2.Truncate(time.Second)}, {timestamp2.Unix(), timestamp2.Truncate(time.Second)},
{timestamp2.UnixNano() / int64(time.Millisecond), timestamp2.Truncate(time.Millisecond)}, {timestamp2.UnixNano() / int64(time.Millisecond), timestamp2.Truncate(time.Millisecond)},