aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Stetson <micah@stetsonnet.org>2012-12-29 14:47:17 -0800
committerMicah Stetson <micah@stetsonnet.org>2012-12-29 14:47:17 -0800
commitf6d10a2a5851307e384c8bb3b9b359bdfccfc613 (patch)
treefb473d76db44f96f27eb47ba84443d3361b4ae6a
parentFix #33 and #34 (diff)
downloadgolite-f6d10a2a5851307e384c8bb3b9b359bdfccfc613.tar.gz
golite-f6d10a2a5851307e384c8bb3b9b359bdfccfc613.tar.xz
Convert times to UTC before storage
-rw-r--r--sqlite3.go2
-rw-r--r--sqlite3_test.go17
2 files changed, 16 insertions, 3 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 87e2cf3..fb446cc 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -213,7 +213,7 @@ func (s *SQLiteStmt) bind(args []driver.Value) error {
}
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(p), C.int(len(v)))
case time.Time:
- b := []byte(v.Format(SQLiteTimestampFormat))
+ b := []byte(v.UTC().Format(SQLiteTimestampFormat))
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
}
if rv != C.SQLITE_OK {
diff --git a/sqlite3_test.go b/sqlite3_test.go
index 3529fe7..5cd61c3 100644
--- a/sqlite3_test.go
+++ b/sqlite3_test.go
@@ -267,6 +267,12 @@ func TestTimestamp(t *testing.T) {
t.Fatal("Failed to insert nonsense:", err)
}
+ timestamp4 := time.Date(2012, time.April, 6, 23, 22, 0, 0, time.FixedZone("TEST", -7*3600))
+ _, err = db.Exec("INSERT INTO foo(id, ts) VALUES(4, ?)", timestamp4)
+ if err != nil {
+ t.Fatal("Failed to insert timestamp:", err)
+ }
+
rows, err := db.Query("SELECT id, ts FROM foo ORDER BY id ASC")
if err != nil {
t.Fatal("Unable to query foo table:", err)
@@ -303,10 +309,17 @@ func TestTimestamp(t *testing.T) {
t.Errorf("Value for id 3 should be the zero time, not %v", ts)
}
}
+
+ if id == 4 {
+ seen += 1
+ if !timestamp4.Equal(ts) {
+ t.Errorf("Value for id 4 should be %v, not %v", timestamp4, ts)
+ }
+ }
}
- if seen != 3 {
- t.Error("Expected to see three timestamps")
+ if seen != 4 {
+ t.Error("Expected to see four timestamps")
}
}