Enforce FixedOffset is a multiple of 60#1036
Enforce FixedOffset is a multiple of 60#1036pitdicker wants to merge 5 commits intochronotope:0.4.xfrom
FixedOffset is a multiple of 60#1036Conversation
|
Haha, the CI pointed out a doctest that used |
|
Hmmm. RFC3339 says:
😞 I will keep this PR open for a little longer for comments. |
Yeah, I would say that, for chrono's goals, historical timestamps are definitely within scope and we should eat the performance trade-offs (unfortunately). But, given that |
|
I am going to work a bit on formatting and parsing offsets. And there is more than one way to create a type with niche. That fits with another experiment. Another attempt in the next days 😄. |
Offsets from UTC are defined in whole hours and minutes, never with seconds.
FixedOffsetstores the offset from UTC in seconds, which makes sense because it allows for fast calculations.I propose to enforce the value of
FixedOffsetis 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
FixedOffsetis always a multiple of 60 enables a nice possibility: it can fit inside ani16if 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
%::zspecifier), I don't expect any issues in real-world uses. But it may trip up some artificial test.