This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-09
Channels
- # adventofcode (132)
- # announcements (19)
- # babashka (7)
- # babashka-sci-dev (6)
- # beginners (46)
- # calva (25)
- # chlorine-clover (5)
- # cider (2)
- # clara (17)
- # clj-kondo (93)
- # clojure (2)
- # clojure-dev (4)
- # clojure-europe (12)
- # clojure-losangeles (3)
- # clojure-nl (7)
- # clojure-uk (4)
- # clojurescript (29)
- # conjure (6)
- # core-async (8)
- # cursive (16)
- # data-science (7)
- # datomic (1)
- # exercism (4)
- # figwheel-main (8)
- # fulcro (9)
- # graphql (2)
- # helix (1)
- # introduce-yourself (3)
- # jobs (3)
- # lsp (4)
- # malli (20)
- # minecraft (3)
- # nextjournal (62)
- # off-topic (16)
- # overtone (34)
- # pathom (5)
- # polylith (10)
- # portal (1)
- # re-frame (104)
- # reagent (29)
- # reitit (1)
- # remote-jobs (2)
- # rum (3)
- # shadow-cljs (22)
- # spacemacs (2)
- # sql (10)
- # tools-deps (17)
- # vim (13)
Anyone happen to have a java.time.ZonedDateTime
to next.jdbc adaptor for postgres lying around? I've found one for the old JDBC but not been able to adapt (heh) it: https://github.com/metabase/metabase/blob/master/src/metabase/db/jdbc_protocols.clj#L60-L62
Just found another of your comments that led me to this:
(extend-protocol next.jdbc.prepare/SettableParameter
java.time.ZonedDateTime
(set-parameter [^java.time.ZonedDateTime zdt ^java.sql.PreparedStatement stmt ^long idx]
(.setTimestamp stmt idx (java.sql.Timestamp/from (jt/instant zdt)))))
The only thing I was wondering about that snippet was the type hint. v isn't an Instant, it's a ZonedDateTime right?
Question I really should answer by doing some proper testing: The timezone is carried over into the SQL timestamp right?
IIRC my code translates between ZDTs on the Clojure side and timestamptz in Postgres. Over the years, I have discovered all kinds of ways to mess up time: • Your local JVM will likely pick up your local timzeone unless you take pains to avoid that • Postgres server may have it's own tz settting. Best to carefully check all this
On the way out of the db, I do something like this:
(extend-protocol result-set/ReadableColumn
java.sql.Timestamp
(read-column-by-label ^java.time.ZonedDateTime [^java.sql.Timestamp v _]
(time/zoned-date-time (time/instant v) "UTC"))
(read-column-by-index ^java.time.ZonedDateTime [^java.sql.Timestamp v _2 _3]
(time/zoned-date-time (time/instant v) "UTC"))