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
30 lines (24 loc) · 826 Bytes
/
clock.clj
File metadata and controls
30 lines (24 loc) · 826 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
28
29
30
(ns java-time.clock
(:require [java-time.core :as jt.c])
(:import [java.time Clock Instant]))
(def ^:dynamic ^Clock *clock* nil)
(defn make [f]
(if *clock*
(f *clock*)
(f (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 [] ~@forms)))