diff options
author | Micah Stetson <micah@stetsonnet.org> | 2012-12-29 16:51:15 -0800 |
---|---|---|
committer | Micah Stetson <micah@stetsonnet.org> | 2012-12-29 16:51:15 -0800 |
commit | 44496728c24982a76893272b23d0c7e949b5818c (patch) | |
tree | 52213678b7cff4949e39e5db8591610029f26fd3 | |
parent | Support time values with nanosecond precision (diff) | |
download | golite-44496728c24982a76893272b23d0c7e949b5818c.tar.gz golite-44496728c24982a76893272b23d0c7e949b5818c.tar.xz |
Support more of the timestamp formats undestood by SQLite
-rw-r--r-- | sqlite3.go | 4 | ||||
-rw-r--r-- | sqlite3_test.go | 22 |
2 files changed, 21 insertions, 5 deletions
@@ -46,7 +46,11 @@ import ( // datetime column, the formats are tried in order. var SQLiteTimestampFormats = []string{ "2006-01-02 15:04:05.999999999", + "2006-01-02T15:04:05.999999999", "2006-01-02 15:04:05", + "2006-01-02T15:04:05", + "2006-01-02 15:04", + "2006-01-02T15:04", "2006-01-02", } diff --git a/sqlite3_test.go b/sqlite3_test.go index a5f324f..9bcc5f3 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -252,18 +252,30 @@ func TestTimestamp(t *testing.T) { timestamp1 := time.Date(2012, time.April, 6, 22, 50, 0, 0, time.UTC) timestamp2 := time.Date(2006, time.January, 2, 15, 4, 5, 123456789, time.UTC) + timestamp3 := time.Date(2012, time.November, 4, 0, 0, 0, 0, time.UTC) tests := []struct { value interface{} expected time.Time }{ - {timestamp1, timestamp1}, - {timestamp1.Unix(), timestamp1}, {"nonsense", time.Time{}}, {"0000-00-00 00:00:00", time.Time{}}, + {timestamp1, timestamp1}, + {timestamp1.Unix(), timestamp1}, {timestamp1.In(time.FixedZone("TEST", -7*3600)), timestamp1}, - {"2012-11-04", time.Date(2012, time.November, 4, 0, 0, 0, 0, time.UTC)}, + {timestamp1.Format("2006-01-02 15:04:05.000"), timestamp1}, + {timestamp1.Format("2006-01-02T15:04:05.000"), timestamp1}, + {timestamp1.Format("2006-01-02 15:04:05"), timestamp1}, + {timestamp1.Format("2006-01-02T15:04:05"), timestamp1}, {timestamp2, timestamp2}, {"2006-01-02 15:04:05.123456789", timestamp2}, + {"2006-01-02T15:04:05.123456789", timestamp2}, + {"2012-11-04", timestamp3}, + {"2012-11-04 00:00", timestamp3}, + {"2012-11-04 00:00:00", timestamp3}, + {"2012-11-04 00:00:00.000", timestamp3}, + {"2012-11-04T00:00", timestamp3}, + {"2012-11-04T00:00:00", timestamp3}, + {"2012-11-04T00:00:00.000", timestamp3}, } for i := range tests { _, err = db.Exec("INSERT INTO foo(id, ts, dt) VALUES(?, ?, ?)", i, tests[i].value, tests[i].value) @@ -293,10 +305,10 @@ func TestTimestamp(t *testing.T) { } seen++ if !tests[id].expected.Equal(ts) { - t.Errorf("Timestamp value for id %v should be %v, not %v", id, tests[id].expected, ts) + t.Errorf("Timestamp value for id %v (%v) should be %v, not %v", id, tests[id].value, tests[id].expected, dt) } if !tests[id].expected.Equal(dt) { - t.Errorf("Datetime value for id %v should be %v, not %v", id, tests[id].expected, dt) + t.Errorf("Datetime value for id %v (%v) should be %v, not %v", id, tests[id].value, tests[id].expected, dt) } } |