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

Use chrono::NaiveDateTime on MySQL timestamp columns #1581

Closed

Conversation

billy1624
Copy link
Contributor

Hi there, I wonder why we couldn't use chrono::NaiveDateTime on a MySQL timestamp column? It should be compatible. Is there any reason behind it? Thanks!!

@abonander
Copy link
Collaborator

abonander commented Dec 27, 2021

Because of the configuration done on startup in MySqlConnectOptions::connect(), TIMESTAMP columns will always be sent and received in UTC.

Allowing a TIMESTAMP to decode as a NaiveDateTime may lead to confusion as it wouldn't match the value that other clients may show when outputting a TIMESTAMP using the local timezone.

If you need to get a NaiveDateTime out of a TIMESTAMP column, I'd recommend doing an explicit conversion with CAST(timestamp_column AT TIME ZONE '-08:00' AS DATETIME) (substituting your UTC offset of choice).

Honestly, we don't touch NaiveDateTime at all in our applications, everything is DateTime<Utc> or time::OffsetDateTime so that there's never any ambiguity.

@billy1624
Copy link
Contributor Author

Thanks!! @abonander

Encoding and decoding as DateTime<Utc> make sense.

@billy1624 billy1624 closed this Dec 28, 2021
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

Successfully merging this pull request may close these issues.

2 participants