mirror of
https://github.com/status-im/timbre.git
synced 2025-03-04 04:51:15 +00:00
Make make-timestamp-fn
thread safe (thanks to jarppe for report)
This commit is contained in:
parent
382f9d4f9a
commit
718f38c462
@ -190,11 +190,14 @@
|
||||
(defn- make-timestamp-fn
|
||||
"Returns a unary fn that formats instants using given pattern string and an
|
||||
optional Locale."
|
||||
;; Thread safe SimpleDateTime soln. from instant.clj, Ref. http://goo.gl/CEBJnQ
|
||||
[^String pattern ^Locale locale]
|
||||
(let [format (if locale
|
||||
(let [format (proxy [ThreadLocal] [] ; For thread safety
|
||||
(initialValue []
|
||||
(if locale
|
||||
(SimpleDateFormat. pattern locale)
|
||||
(SimpleDateFormat. pattern))]
|
||||
(fn [^Date instant] (.format ^SimpleDateFormat format instant))))
|
||||
(SimpleDateFormat. pattern))))]
|
||||
(fn [^Date instant] (.format ^SimpleDateFormat (.get format) instant))))
|
||||
|
||||
(comment ((make-timestamp-fn "yyyy-MMM-dd" nil) (Date.)))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user