Fix for PostgreSQL timestamp with timezone fields.

The previous fix for PostgreSQL timestamp fields matched fields with and
without timezones, but did not properly parse values from fields that
included the timezone. Now we check for the presence of the timezone in
the date string and choose a format string to parse it correctly.
This commit is contained in:
Jonathan Bernard 2021-07-05 11:24:06 -05:00
parent 445c86f97e
commit 2b78727356
2 changed files with 8 additions and 5 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "0.3.1"
version = "0.3.2"
author = "Jonathan Bernard"
description = "Lightweight Postgres ORM for Nim."
license = "GPL-3.0"

View File

@ -90,11 +90,14 @@ proc parsePGDatetime*(val: string): DateTime =
if match.isSome:
let c = match.get.captures
try:
let corrected = c[0] & alignLeft(c[1], 3, '0') & c[2]
return corrected.parse(PG_TIMESTAMP_FORMATS[1])
if c.toSeq.len == 2:
let corrected = c[0] & alignLeft(c[1], 3, '0')
return corrected.parse(PG_TIMESTAMP_FORMATS[2])
else:
let corrected = c[0] & alignLeft(c[1], 3, '0') & c[2]
return corrected.parse(PG_TIMESTAMP_FORMATS[3])
except:
errStr &= "\n\t" & PG_TIMESTAMP_FORMATS[1] &
" after padding out milliseconds to full 3-digits"
errStr &= "\n\t" & getCurrentExceptionMsg()
raise newException(ValueError, "Cannot parse PG date. Tried:" & errStr)