Enforce FixedOffset
is a multiple of 60
#1036
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Offsets from UTC are defined in whole hours and minutes, never with seconds.
FixedOffset
stores the offset from UTC in seconds, which makes sense because it allows for fast calculations.I propose to enforce the value of
FixedOffset
is always a multiple of 60.This prevents a number of existing or potential problems:
hh::mm::ss
.I mainly want to make this change because it prevents those problems.
Enforcing
FixedOffset
is always a multiple of 60 enables a nice possibility: it can fit inside ani16
if we shift the value 2 bits (which we can, 60 is divisable by 4). This creates room for niche optimization:<Option<DateTime<FixedOffset>>>
now only requires 16 bytes instead of 20.Could this effect users of chrono?
It is pretty much a rule that whenever you start checking something you didn't before, it catches some problems. Because Unix, Windows and the IANA timezone database don't allow seconds to define offsets, and because chrono can barely parse them (only with the
%::z
specifier), I don't expect any issues in real-world uses. But it may trip up some artificial test.