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

Fix assume timezone #8

Merged
merged 10 commits into from
Apr 10, 2022
Merged

Fix assume timezone #8

merged 10 commits into from
Apr 10, 2022

Conversation

Yuri6037
Copy link
Owner

@Yuri6037 Yuri6037 commented Apr 10, 2022

This PR finally fixes the behavior of assume_timezone and assume_timezone_utc. The assume_timezone function is now fixed to always assume the input PrimitiveDateTime is already in the target timezone. The assume_timezone_utc preserves the old behavior of assuming the input PrimitiveDateTime is actually in UTC.

Fixes #5
Fixes #6

@korrat
Copy link

korrat commented Apr 10, 2022

FYI, if you want to prevent traits like PrimitiveDateTimeExt from being implemented outside your crate, you can seal them with a trick. Basically, you add a trait to a private module in your crate and use it as a trait bound on your public traits. Since the trait in the private module is not visible outside your crate, nobody can implement it outside your crate. Therefore, outside your crate, nobody can implement the public traits either. The Rust API Guidelines have a bit more details on that.

@Yuri6037
Copy link
Owner Author

FYI, if you want to prevent traits like PrimitiveDateTimeExt from being implemented outside your crate, you can seal them with a trick. Basically, you add a trait to a private module in your crate and use it as a trait bound on your public traits. Since the trait in the private module is not visible outside your crate, nobody can implement it outside your crate. Therefore, outside your crate, nobody can implement the public traits either. The Rust API Guidelines have a bit more details on that.

Wow thanks a lot I had no idea this existed. I'll try looking into this.

…d a crate feature to allow using of the timezone utilities in the library instead of pulling the entire IANA db.
@Yuri6037
Copy link
Owner Author

I've applied the new API changes with the sealed trait trick. I've also included a feature to allow removing the tz database with this 1.0 release. The feature is there in case you wanted to use your own custom timezone database or maybe even use the system database instead of the built-in one.

@Yuri6037 Yuri6037 merged commit fe33fc1 into master Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants