Skip to content

Instantly share code, notes, and snippets.

@defndaines
Created February 19, 2018 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defndaines/0b5c37c8c585e975d8c5b70271a1dce1 to your computer and use it in GitHub Desktop.
Save defndaines/0b5c37c8c585e975d8c5b70271a1dce1 to your computer and use it in GitHub Desktop.
Set up #inst and #date for Clojure to use java.time libraries
(defmethod print-method java.time.LocalDate
[v ^java.io.Writer w]
(.write w "#date \"")
(.write w (.format v java.time.format.DateTimeFormatter/ISO_LOCAL_DATE))
(.write w "\""))
(java.time.LocalDate/now)
(defn format-instant
[v ^java.io.Writer w]
(.write w "#inst \"")
(.write w (.format v java.time.format.DateTimeFormatter/ISO_INSTANT))
(.write w "\""))
(defmethod print-method java.time.ZonedDateTime
[v ^java.io.Writer w]
(format-instant v w))
(defmethod print-method java.time.Instant
[v ^java.io.Writer w]
(format-instant (.atZone v (java.time.ZoneId/of "UTC")) w))
(java.time.ZonedDateTime/now)
(java.time.Instant/now)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment