Created
February 19, 2018 15:05
-
-
Save defndaines/0b5c37c8c585e975d8c5b70271a1dce1 to your computer and use it in GitHub Desktop.
Set up #inst and #date for Clojure to use java.time libraries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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