dm3 / clojure.java-time

Java 8 Date-Time API for Clojure
MIT License
461 stars 45 forks source link

`zoned-date-time` with a single argument does not use `java-time.clock/make` #100

Closed pjstadig-sovasage closed 11 months ago

pjstadig-sovasage commented 11 months ago

If I establish a clock with with-clock and call zoned-date-time with zero args I get the value from the clock:

user> (jt/zoned-date-time)
#object[java.time.ZonedDateTime 0xec87f3d "2023-07-27T17:30:26.503112-04:00[America/New_York]"]
user> (jt/with-clock (jt/fixed-clock (jt/zoned-date-time 1999 9 9 9 0)) (jt/zoned-date-time))
#object[java.time.ZonedDateTime 0x4ccb1edd "1999-09-09T09:00-04:00[America/New_York]"]

However, if I specify only a timezone, it uses the system clock:

user> (jt/with-clock (jt/fixed-clock (jt/zoned-date-time 1999 9 9 9 0)) (jt/zoned-date-time (jt/zone-id "-07:00")))
#object[java.time.ZonedDateTime 0x2e155218 "2023-07-27T14:31:33.207772-07:00"]

I can work around this by constructing a zoned-date-time with zero args and passing that to zoned-date-time with a zone:

user> (jt/with-clock (jt/fixed-clock (jt/zoned-date-time 1999 9 9 9 0)) (jt/zoned-date-time (jt/zoned-date-time) (jt/zone-id "-07:00")))
#object[java.time.ZonedDateTime 0x14db2a54 "1999-09-09T06:00-07:00"]

I would have expected calling zoned-date-time with a timezone to use java-time.clock/*clock* instead of the system clock. Inspecting the code it looks like the single-arg-zone case for zoned-date-time is just calling (java.time.ZonedDateTime/now zone) which uses the system clock according to the documentation.

There's a similar issue with offset-date-time and offset-time and maybe others, I didn't inspect everything.

pjstadig-sovasage commented 11 months ago

:tada: