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

Store datetimes with fixed offset #378

Merged
merged 1 commit into from
Feb 23, 2024
Merged

Store datetimes with fixed offset #378

merged 1 commit into from
Feb 23, 2024

Conversation

sharkdp
Copy link
Owner

@sharkdp sharkdp commented Feb 23, 2024

This changes a couple of things regarding datetime handling:

  • We don't store utc datetime and offset separately, but as a single DateTime. This not just fixes a bug, but also feels much cleaner overall.
  • Do not ignore offsets in format_datetime, fixes Support for RFC 3339 in target time zone #376
  • Fix crashes for out-of-range values in from_unixtime
  • datetime(…) will now return datetimes with the specified UTC offset (not the local UTC offset)
  • from_unixtime(…) will now return datetimes in the local timezone, not in UTC

@@ -26,7 +28,7 @@ pub enum Value {
Boolean(bool),
String(String),
/// A DateTime with an associated offset used when pretty printing
DateTime(chrono::DateTime<chrono::Utc>, chrono::FixedOffset),
DateTime(chrono::DateTime<chrono::FixedOffset>),
Copy link
Owner Author

Choose a reason for hiding this comment

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

@eminence Do you remember why you chose to store datetime in UTC + offset separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, not really. I think the initial version didn't support any datetime conversions, so storing a DateTime<Utc> was a natural fit, and it didn't evolve in the best way when Tz conversions were added. I may have also been operating under [a potentially faulty] assumption that it would be easier to reason about datetime operations is everything was done in Utc (and then only converted to something else for printing).

However skimming your new version here, it does look less complicated 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you!

@sharkdp sharkdp merged commit e5c5bd9 into master Feb 23, 2024
15 checks passed
@sharkdp sharkdp deleted the fix-376 branch February 23, 2024 22:58
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.

Support for RFC 3339 in target time zone
2 participants