forked from dm3/clojure.java-time
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.clj
More file actions
27 lines (21 loc) · 782 Bytes
/
clock.clj
File metadata and controls
27 lines (21 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(ns java-time.clock
(:import [java.time Clock]))
(def ^:dynamic ^Clock *clock* nil)
(defn make [f]
(f (or *clock* (Clock/systemDefaultZone))))
(defn with-clock-fn
"Executes the given function in the scope of the provided clock. All the
temporal entities that get created without parameters will inherit their
values from the clock."
[^Clock c f]
(binding [*clock* c]
(f)))
(defmacro with-clock
"Executes the given `forms` in the scope of the provided `clock`.
All the temporal entities that get created without parameters will inherit
their values from the clock:
(with-clock (system-clock \"Europe/London\")
(zone-id))
=> #<java.time.ZoneRegion Europe/London>"
[c & forms]
`(with-clock-fn ~c (fn [] (let [res# (do ~@forms)] res#))))