diff options
author | Ian Bishop <ianbishop@pace7.com> | 2015-01-02 16:31:46 +1000 |
---|---|---|
committer | Ian Bishop <ianbishop@pace7.com> | 2015-01-02 16:42:25 +1000 |
commit | 0b05acc293a940d3bfedf2df5fba12c49ac9ec35 (patch) | |
tree | 6a88e73baf2b64650b48cb2c6e84e0b1c4fcd86f /sqlite3.go | |
parent | Revert d369cbb7d42232f785f51b3ef4c8b994dae83486 (diff) | |
download | golite-0b05acc293a940d3bfedf2df5fba12c49ac9ec35.tar.gz golite-0b05acc293a940d3bfedf2df5fba12c49ac9ec35.tar.xz |
Handle 13 digit datetime values
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -64,6 +64,7 @@ import ( "fmt" "io" "runtime" + "strconv" "strings" "time" "unsafe" @@ -504,7 +505,18 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { val := int64(C.sqlite3_column_int64(rc.s.s, C.int(i))) switch rc.decltype[i] { case "timestamp", "datetime", "date": - dest[i] = time.Unix(val, 0).Local() + unixTimestamp := strconv.FormatInt(val, 10) + if len(unixTimestamp) == 13 { + duration, err := time.ParseDuration(unixTimestamp + "ms") + if err != nil { + return fmt.Errorf("error parsing %s value %d, %s", rc.decltype[i], val, err) + } + epoch := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC) + dest[i] = epoch.Add(duration) + } else { + dest[i] = time.Unix(val, 0).Local() + } + case "boolean": dest[i] = val > 0 default: |