When I read postgres date types, I want them to be coerced into joda time LocalDates (or the new java.time localdates). This is because postgres dates does not have time zone info, so I don't want my java or clojure object to add it somehow.
This is the IResultSetReadColumn protocol extension I've set up for this:
(extend-protocol clojure.java.jdbc/IResultSetReadColumn
java.sql.Date
(result-set-read-column [v _rsmeta _idx]
(tc/to-local-date v)))
However, when I try to use it, I get the wrong result:
(DateTimeZone/getDefault)
=> #object[org.joda.time.tz.CachedDateTimeZone 0x60470ff "Europe/Stockholm"]
(jdbc/query db/db ["SHOW TIMEZONE"])
=> ({:timezone "Europe/Stockholm"})
(jdbc/query db/db ["SELECT '2020-01-01'::date"])
=> ({:date #object[org.joda.time.LocalDate 0x75081795 "2019-12-31"]}) ; ARGH!! It changed date!
I suspect this is caused by the dates being converted into java.sql.date, which has timezone info in it somehow. Is there perhaps a way to read the postgres dates directly to avoid this? I've found documentation on the postgres JDBC driver that seems promising but I can't figure out how to implement it in clojure.java.jdbc.
Basically: Is there any way to get my postgres dates out of the database without messing them up, if my default timezone is not UTC?