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

Convert OffsetDateTime back to PrimitiveDateTime #390

Closed
therustmonk opened this issue Nov 9, 2021 · 2 comments
Closed

Convert OffsetDateTime back to PrimitiveDateTime #390

therustmonk opened this issue Nov 9, 2021 · 2 comments
Labels
A-core Area: anything not otherwise covered C-feature-request Category: a new feature (not already implemented)

Comments

@therustmonk
Copy link

I know there are some discussions about converting OffsetDateTime to PrimitiveDateTime, but there is no a way to do that simply.

Since chrono used old version of time some projects considered to switch directly to the latest time crate, but there is a problem: chrono provides naive_local and naive_utc methods, and it's not easy to use time directly if the project uses NaiveDateTime and already stored some data using that format (without timezone).

Is there any reason we don't have From<OffsetDateTime> for PrimitiveDateTime implementation? It could help to move from the chrono crate easier.

@jhpratt
Copy link
Member

jhpratt commented Nov 9, 2021

if the project uses NaiveDateTime and already stored some data using that format (without timezone).

That's the problem. You're trying to use PrimitiveDateTime for something where you should be using OffsetDateTime. impl From<OffsetDateTime> for PrimitiveDateTime won't be added in any situation because there is no UtcOffset that is always correct.

This was recently requested in #369. There is no reason that I see that you can't use .date() and .time(), recombining them into a PrimitiveDateTime if that's what you truly want. In #369 benchmarks were raised, but those were flawed. These methods aren't guaranteed to be free, regardless.

@jhpratt jhpratt added A-core Area: anything not otherwise covered C-feature-request Category: a new feature (not already implemented) labels Nov 9, 2021
@therustmonk
Copy link
Author

@jhpratt Thanks 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: anything not otherwise covered C-feature-request Category: a new feature (not already implemented)
Projects
None yet
Development

No branches or pull requests

2 participants