Mateus Q
Mateus Q

Reputation: 21

How to properly set a timezone in a clojure REPL?

When running a query on a postgres database on a clojure REPL, the timestamps fields are presented in UTC and I need them to be in timezone America/Sao_Paulo (UTC-3)

So far I have tried the following on Intellij's REPL:

and the following on Leiningen REPL:

None worked so far!

Sample code

(ns experiments
  (:require [next.jdbc :as jdbc]))

(def db
  {:dbtype   "postgres"
   :dbname   "<dbname>"
   :host     "<host>"
   :port     5432
   :user     "<user>"
   :password "<pass>"})

(def ds (jdbc/get-datasource db))

(jdbc/execute! ds ["select current_timestamp"])

Upvotes: 2

Views: 543

Answers (1)

Alan Thompson
Alan Thompson

Reputation: 29958

You did not mention any Postgres options. Please study this page carefully for info and options.

If the above does not solve your problem, it may be easiest to use java.time to do the conversion. I also have some helper/convenience functions available here. Unit tests show them in action, and the source code provides examples of java.time interop from clojure.

I would avoid the older Joda Time libraries as they are obsolete (replaced by java.time). I think that Java interop is the easiest & most straightforward way to access java.time.

Upvotes: 1

Related Questions