Yuri6037 / time-tz

Implementation of tz database (IANA) for time Rust crate.
BSD 3-Clause "New" or "Revised" License
22 stars 7 forks source link

Add a fallible timezone conversion method #22

Open mzabaluev opened 7 months ago

mzabaluev commented 7 months ago

The to_timezone method returns OffsetDateTime. Its implementation uses OffsetDateTime::to_offset which may panic if the resulting date is out of range. There is also the fallible OffsetDateTime::checked_to_offset, so it would be nice to provide a checked time zone conversion method using that, for people concerned about the Y10K problem :grin:

Since the extension trait is sealed, a new method can be added as a non-breaking change.

Yuri6037 commented 7 months ago

The to_timezone method returns OffsetDateTime. Its implementation uses OffsetDateTime::to_offset which may panic if the resulting date is out of range. There is also the fallible OffsetDateTime::checked_to_offset, so it would be nice to provide a checked time zone conversion method using that, for people concerned about the Y10K problem 😁

I've updated the docs in master and added a new checked_to_timezone function.

Since the extension trait is sealed, a new method can be added as a non-breaking change.

Well since in master I've moved to_timezone to its own trait (not sealed) it's now a breaking change, fortunately it's only a breaking change from 1 pre-release to another (master is on 3.0.0-rc.2.0.0 now).

mzabaluev commented 7 months ago

Well since in master I've moved to_timezone to its own trait (not sealed) it's now a breaking change

Ah! So now the unchecked method can be provided in the trait by default, implemented through the checked method.

Yuri6037 commented 7 months ago

Well since in master I've moved to_timezone to its own trait (not sealed) it's now a breaking change

Ah! So now the unchecked method can be provided in the trait by default, implemented through the checked method.

Not exactly because of the OutChecked type used to allow implementing checked_to_timezone on things like PosixTz or &str.