juxt / tick

Time as a value.
MIT License
599 stars 57 forks source link

date-time -> inst conversion doesn't respect clock #49

Closed maxthoursie closed 5 years ago

maxthoursie commented 5 years ago

Converting a date-time to a inst doesn't respect a clock binding. It uses the system default zone instead.

(t/with-clock (t/in (t/clock) "Pacific/Honolulu")
 (-> (t/date-time "2019-08-07T12:00") (t/inst)))
=> #inst"2019-08-07T10:00:00.000-00:00"

The expected answer is 22:00

(-> (t/zoned-date-time "2019-08-07T12:00-10:00[Pacific/Honolulu]") (t/inst))
=> #inst"2019-08-07T22:00:00.000-00:00"

The reverse conversion does respect the clock

(t/with-clock (t/in (t/clock) "Pacific/Honolulu")
              (t/zoned-date-time #inst"2019-08-07T22:00"))
=> #time/zoned-date-time"2019-08-07T12:00-10:00[Pacific/Honolulu]"

If you agree this is an error I'd be happy to provide a patch.

malcolmsparks commented 5 years ago

Yes, this does look like an error - I'd like to see the patch if it's fairly easy to make and discuss with @henryw374

henryw374 commented 5 years ago

Thanks for the patch. Now merged in.