Skip to content
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

Add a fallible timezone conversion method #22

Open
mzabaluev opened this issue Feb 29, 2024 · 3 comments
Open

Add a fallible timezone conversion method #22

mzabaluev opened this issue Feb 29, 2024 · 3 comments

Comments

@mzabaluev
Copy link

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 😁

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

@Yuri6037
Copy link
Owner

Yuri6037 commented Mar 1, 2024

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
Copy link
Author

mzabaluev commented Mar 1, 2024

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
Copy link
Owner

Yuri6037 commented Mar 1, 2024

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.

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

No branches or pull requests

2 participants