Skip to content

Commit b10a1fa

Browse files
committed
Fix #100: respect *clock* when providing zone id
1 parent 98bafb7 commit b10a1fa

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## NEXT
44

55
- remove `:redef` on protocol methods, they are never direct-linked: https://ask.clojure.org/index.php/10967/are-protocol-methods-guaranteed-to-not-be-directly-linked?show=10990#a10990
6+
- [#100](https://github.com/dm3/clojure.java-time/issues/100): respect `*clock*` when only providing a zone id in constructors
67

78
## 1.2.0
89

Diff for: src/java_time/zone.clj

+9-3
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,23 @@
200200

201201
(conversion! ZoneId ZonedDateTime
202202
(fn [^ZoneId z]
203-
(ZonedDateTime/now z))
203+
(jt.clock/make
204+
(fn [^Clock c]
205+
(ZonedDateTime/now (.withZone c z)))))
204206
2)
205207

206208
(conversion! ZoneId OffsetDateTime
207209
(fn [^ZoneId z]
208-
(OffsetDateTime/now z))
210+
(jt.clock/make
211+
(fn [^Clock c]
212+
(OffsetDateTime/now (.withZone c z)))))
209213
2)
210214

211215
(conversion! ZoneId OffsetTime
212216
(fn [^ZoneId z]
213-
(OffsetTime/now z))
217+
(jt.clock/make
218+
(fn [^Clock c]
219+
(OffsetTime/now (.withZone c z)))))
214220
2)
215221

216222
(conversion! CharSequence ZonedDateTime

Diff for: test/java_time/api_test.clj

+17-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
'[java-time.util :as jt.u])
1010
(import java.util.Locale)
1111

12-
(def clock (j/fixed-clock "2015-11-26T10:20:30.000000040Z" "UTC"))
12+
(def ^java.time.Clock clock (j/fixed-clock "2015-11-26T10:20:30.000000040Z" "UTC"))
1313

1414
(deftest constructors-test
1515
(testing "clocks"
1616
(testing ", with-clock"
17+
(is (= (j/with-clock clock (j/zone-offset))
18+
(j/with-clock-fn clock j/zone-offset)
19+
(j/zone-offset clock)))
1720
(are [f] (= (j/with-clock clock (f))
21+
(j/with-clock clock (f (j/zone-id "UTC")))
1822
(j/with-clock-fn clock f)
1923
(f clock))
2024
j/zoned-date-time
@@ -23,8 +27,18 @@
2327
j/local-date-time
2428
j/local-time
2529
j/local-date
26-
j/zone-offset
27-
j/zone-id))
30+
j/zone-id)
31+
(doseq [offset ["+01:00" "-01:00"]]
32+
(testing offset
33+
(are [f] (= (j/with-clock clock (f (j/zone-id offset)))
34+
(f (.withZone clock (j/zone-id offset))))
35+
j/zoned-date-time
36+
j/offset-date-time
37+
j/offset-time
38+
j/local-date-time
39+
j/local-time
40+
j/local-date
41+
j/zone-id))))
2842

2943
(testing ", system"
3044
(let [now-millis (j/value (j/system-clock))]

0 commit comments

Comments
 (0)