Preserve DateTime microsecond precision
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import std/[os, times, unittest]
|
||||
import db_connector/[db_common, db_postgres]
|
||||
|
||||
import fiber_orm/util
|
||||
|
||||
proc utcDateTime(nanosecond: NanosecondRange): DateTime =
|
||||
dateTime(
|
||||
2026, mAug, 26, 14, 32, 10, nanosecond,
|
||||
utc())
|
||||
|
||||
let connectionString = getEnv("FIBER_ORM_TEST_DB")
|
||||
if connectionString.len == 0:
|
||||
quit "FIBER_ORM_TEST_DB must contain a PostgreSQL connection string"
|
||||
|
||||
suite "PostgreSQL DateTime round trips":
|
||||
test "preserves whole-second, millisecond, and microsecond values":
|
||||
let db = db_postgres.open("", "", "", connectionString)
|
||||
defer: db.close()
|
||||
db.exec(sql"SET TIME ZONE 'UTC'")
|
||||
|
||||
for expected in [
|
||||
utcDateTime(0),
|
||||
utcDateTime(123_000_000),
|
||||
utcDateTime(123_457_000),
|
||||
]:
|
||||
let dbValue = db.getValue(
|
||||
sql"SELECT ?::timestamp with time zone",
|
||||
dbFormat(expected))
|
||||
let actual = parsePGDatetime(dbValue)
|
||||
check actual.toTime == expected.toTime
|
||||
Reference in New Issue
Block a user