Skip to content

Commit

Permalink
Remove format hack in favor of java.time
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored and brandonbloom committed Apr 15, 2022
1 parent 4219401 commit efdf87f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 0 additions & 5 deletions src/fipp/ednize.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
id (format "0x%x" (System/identityHashCode o))]
(tagged-literal 'object [cls id rep])))

(defn format-hack [v x]
(let [local ^java.lang.ThreadLocal @v
fmt ^java.text.SimpleDateFormat (.get local)]
(.format fmt x)))

(extend-protocol IEdn

nil
Expand Down
17 changes: 12 additions & 5 deletions src/fipp/ednize/instant.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
(ns fipp.ednize.instant
"Provides features that may not be available under every Clojure / JVM combination."
(:require [clojure.instant]
[fipp.ednize :refer [IEdn format-hack]])
(:require [fipp.ednize :refer [IEdn]])
(:import (java.sql Timestamp)
(java.util Date)))
(java.util Date)
(java.time.format DateTimeFormatter)
(java.time ZoneId)))

(set! *warn-on-reflection* true)

(def date-pattern (DateTimeFormatter/ofPattern "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00"))

(extend-protocol IEdn
Timestamp
(-edn [x]
(let [s (format-hack #'clojure.instant/thread-local-utc-timestamp-format x)]
(let [dt (-> x .toInstant (.atZone (ZoneId/of "GMT")))
s (.format dt DateTimeFormatter/ISO_LOCAL_DATE_TIME)]
(tagged-literal 'inst s)))

Date
(-edn [x]
(let [s (format-hack #'clojure.instant/thread-local-utc-date-format x)]
(let [dt (-> x .toInstant (.atZone (ZoneId/of "GMT")))
s (.format dt date-pattern)]
(tagged-literal 'inst s))))

0 comments on commit efdf87f

Please sign in to comment.