diff --git a/CHANGELOG.md b/CHANGELOG.md index d3018c3..df9a342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## NEXT - 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 +- [#100](https://github.com/dm3/clojure.java-time/issues/100): respect `*clock*` when only providing a zone id in constructors ## 1.2.0 diff --git a/src/java_time/zone.clj b/src/java_time/zone.clj index ddfaf17..334b632 100644 --- a/src/java_time/zone.clj +++ b/src/java_time/zone.clj @@ -200,17 +200,23 @@ (conversion! ZoneId ZonedDateTime (fn [^ZoneId z] - (ZonedDateTime/now z)) + (jt.clock/make + (fn [^Clock c] + (ZonedDateTime/now (.withZone c z))))) 2) (conversion! ZoneId OffsetDateTime (fn [^ZoneId z] - (OffsetDateTime/now z)) + (jt.clock/make + (fn [^Clock c] + (OffsetDateTime/now (.withZone c z))))) 2) (conversion! ZoneId OffsetTime (fn [^ZoneId z] - (OffsetTime/now z)) + (jt.clock/make + (fn [^Clock c] + (OffsetTime/now (.withZone c z))))) 2) (conversion! CharSequence ZonedDateTime diff --git a/test/java_time/api_test.clj b/test/java_time/api_test.clj index b356823..566abdd 100644 --- a/test/java_time/api_test.clj +++ b/test/java_time/api_test.clj @@ -9,12 +9,16 @@ '[java-time.util :as jt.u]) (import java.util.Locale) -(def clock (j/fixed-clock "2015-11-26T10:20:30.000000040Z" "UTC")) +(def ^java.time.Clock clock (j/fixed-clock "2015-11-26T10:20:30.000000040Z" "UTC")) (deftest constructors-test (testing "clocks" (testing ", with-clock" + (is (= (j/with-clock clock (j/zone-offset)) + (j/with-clock-fn clock j/zone-offset) + (j/zone-offset clock))) (are [f] (= (j/with-clock clock (f)) + (j/with-clock clock (f (j/zone-id "UTC"))) (j/with-clock-fn clock f) (f clock)) j/zoned-date-time @@ -23,8 +27,18 @@ j/local-date-time j/local-time j/local-date - j/zone-offset - j/zone-id)) + j/zone-id) + (doseq [offset ["+01:00" "-01:00"]] + (testing offset + (are [f] (= (j/with-clock clock (f (j/zone-id offset))) + (f (.withZone clock (j/zone-id offset)))) + j/zoned-date-time + j/offset-date-time + j/offset-time + j/local-date-time + j/local-time + j/local-date + j/zone-id)))) (testing ", system" (let [now-millis (j/value (j/system-clock))]