Skip to content

Commit 8a4c825

Browse files
authored
Merge pull request #431 from deepilla/issue-430
Don't convert Unix times to nanoseconds when querying datetime fields…
2 parents afe454f + 0512385 commit 8a4c825

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

sqlite3.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,10 +961,11 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
961961
// large to be a reasonable timestamp in seconds.
962962
if val > 1e12 || val < -1e12 {
963963
val *= int64(time.Millisecond) // convert ms to nsec
964+
t = time.Unix(0, val)
964965
} else {
965-
val *= int64(time.Second) // convert sec to nsec
966+
t = time.Unix(val, 0)
966967
}
967-
t = time.Unix(0, val).UTC()
968+
t = t.UTC()
968969
if rc.s.c.loc != nil {
969970
t = t.In(rc.s.c.loc)
970971
}

sqlite3_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ func TestTimestamp(t *testing.T) {
403403
}{
404404
{"nonsense", time.Time{}},
405405
{"0000-00-00 00:00:00", time.Time{}},
406+
{time.Time{}.Unix(), time.Time{}},
406407
{timestamp1, timestamp1},
407408
{timestamp2.Unix(), timestamp2.Truncate(time.Second)},
408409
{timestamp2.UnixNano() / int64(time.Millisecond), timestamp2.Truncate(time.Millisecond)},

0 commit comments

Comments
 (0)