Skip to content

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

Closed

Description

@pjstadig-sovasage

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.

Activity

  1. 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`[/+] on Aug 11, 2023
  2. added a commit that references this issue on Aug 11, 2023
    b10a1fa
  3. added a commit that references this issue on Aug 11, 2023
    c720542
  4. pjstadig-sovasage commented on Aug 11, 2023

    @pjstadig-sovasage
    Author

    🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions