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

Support the use of chrono::DateTime<Utc> using the type alias DateTim… #222

Merged
merged 6 commits into from
Jan 16, 2022

Conversation

charleschege
Copy link
Contributor

Support DateTime natively.

After researching and diving into the code, I found that the best way is to convert the DateTime<Utc> into a DateTime<FixedOffset> with the FixedOffset being based on chrono::Utc . This is helpful especially in databases like MySQL which store the TIMESTAMP in UTC despite a timezone being specified.

…eUtc

Add a test to ensure the DateTimeUtc is parsed and converted to SQL equivalent of TIMESTAMP
@charleschege
Copy link
Contributor Author

@billy1624 @tyt2y3 Any thoughts on this are welcome

src/value.rs Outdated Show resolved Hide resolved
@billy1624
Copy link
Member

Btw... we have to update src/driver/*.rs to bind the new Value::DateTimeUtc correctly

Move FixedOffset to its own `From` implementation

Implement test for Utc
@charleschege
Copy link
Contributor Author

@billy1624 I have moved the DateTime<FixedOffset> into its own From trait. I hope that's okay. Also, I am wondering about the correctness of the src/drivers code I have introduced. Comments are welcome

src/value.rs Outdated
Comment on lines 597 to 603
#[cfg(feature = "with-chrono")]
pub fn as_ref_date_time_utc(&self) -> Option<String> {
match self {
Self::DateTimeUtc(v) => v.as_ref().map(|v| v.naive_utc().to_string()),
_ => panic!("not Value::DateTimeUtc"),
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here should return Option<&DateTime<Utc>> instead of serializing it as string

@tyt2y3 tyt2y3 changed the base branch from master to datetime-utc January 16, 2022 14:19
@tyt2y3 tyt2y3 merged commit 44aa114 into SeaQL:datetime-utc Jan 16, 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
Development

Successfully merging this pull request may close these issues.

3 participants