-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove format hack in favor of java.time
- Loading branch information
1 parent
45c9496
commit ca9b107
Showing
2 changed files
with
12 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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)))) |