Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pjstadig-sovasage opened this issue Jul 27, 2023 · 1 comment · Fixed by #101
Closed

Comments

@pjstadig-sovasage
Copy link

pjstadig-sovasage commented Jul 27, 2023

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.

@frenchy64 frenchy64 changed the title zoned-date-time with a singe argument does not use java-time.clock/make zoned-date-time with a single argument does not use java-time.clock/make Aug 11, 2023
@pjstadig-sovasage
Copy link
Author

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant