Skip to content

Fix/sqlite time utc - #32

Merged
juicycleff merged 4 commits into
mainfrom
fix/sqlite-time-utc
Oct 2, 2026
Merged

juicycleff merged 4 commits into
mainfrom
fix/sqlite-time-utc

Conversation

@juicycleff

Copy link
Copy Markdown
Contributor

No description provided.

modernc.org/sqlite binds a time.Time with t.String() unless the DSN sets
_time_format. That appends " m=+86400.02..." whenever the value still
carries a monotonic reading, which any time.Now().Add(...) does, and it
prints a zone with no name as "+0200 +0200". parseTimeString accepted
neither. It fails inside Scan, so one bad row failed the whole query.
Range filters broke too: WHERE at < ? compares TEXT, and a non-UTC
argument matched the wrong rows.

The sqlite driver now converts time.Time, *time.Time and valid
sql.NullTime args to UTC in utcArgs, at the three places args reach
database/sql: SqliteDB outside a transaction, sqliteTx and sqliteStmt.
That covers inserts, bulk inserts, updates, WHERE args and raw queries
without touching the builders. The caller's slice is copied and left
alone, because RawQuery reuses its args and hooks see qc.RawArgs.

parseTimeString strips the monotonic suffix and has a layout for the
doubled offset, so rows already written that way scan again. That part
lives in scan, so turso gets it as well.

sql.NullTime fields couldn't read sqlite at all. NullTime.Scan only takes
a time.Time and sqlite hands back a string, so even a clean named-zone
value failed. scan now wraps it the same way it wraps time.Time.

Old rows keep whatever zone they were written in, and new rows are UTC.
A table holding both sorts lexically wrong across the two until the old
rows are rewritten. Defaulting _time_format=sqlite has the same problem,
which is why this doesn't.

drivers/sqlitedriver/time_roundtrip_test.go round-trips a monotonic
time, a nameless offset and a named zone through insert, bulk insert,
update and a transaction, for time.Time, *time.Time and sql.NullTime.
It checks the stored text directly too, since the scan fix alone makes a
round trip pass whatever the write side does.
extension was on v1.10.0 and kv/extension on v1.9.8, so the two had
drifted apart. Both now require v1.11.2. go mod tidy also moved confy to
v1.0.3 and go-utils to v1.3.0, bumped golang.org/x/crypto, net and text
in kv/extension, and dropped zap and multierr, which forge no longer
pulls in.
@juicycleff
juicycleff merged commit b233c5f into main Oct 2, 2026
8 checks passed
@juicycleff
juicycleff deleted the fix/sqlite-time-utc branch October 2, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant