I used next.jdbc library to persist a record to a PostgreSQL table. As you can see below, the values are a LocalDate instance and an Instant instance. The SQL columns are of type DATE and TIMESTAMPTZ respectively.
Required the next.jdbc.date-time
namespace to map from Java -> SQL, as mentioned in the docs.
{:id 7, :trade_date #object[java.time.LocalDate 0x6b751cb1 2020-12-22], :created_at #object[java.time.Instant 0x3add5e17 2020-12-22T11:41:07.557790Z]}
When I read the record back (SQL -> Clojure), the representation is as follows
{:id 7, :trade_date #inst "2020-12-21T18:30:00.000-00:00", :created_at #inst "2020-12-22T11:41:07.557790000-00:00"}
So they are read back as #inst literals? I'd like them back as java.time types. Also note that the LocalDate seems to be converted to a UTC timestamp. Here's what I dug up so far..
; inst -> Instant
=> (.toInstant #inst "2020-12-22T11:41:07.557790000-00:00")
#object[java.time.Instant 0x312cc79e "2020-12-22T11:41:07.557Z"]
; inst -> LocalDate
=> (-> #inst "2020-12-21T18:30:00.000-00:00"
#_=> .toInstant
#_=> (ZonedDateTime/ofInstant (ZoneId/of "UTC"))
#_=> (.withZoneSameInstant (ZoneId/systemDefault))
#_=> (.toLocalDate))
#object[java.time.LocalDate 0x44048462 "2020-12-22"]
Doesn't seem simple / the Clojure way. Is there a better way?
References: Pieced from the answers by Alan Thompson and Basil Bourque