tz: add Offset::round
and fix Africa/Monrovia
parsing
#234
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.
This adds a new
Offset::round
API in order to support fixing #231.Namely, previously, we would fail to parse zoned datetimes
like
1969-12-31T23:15:30-00:45[Africa/Monrovia]
becauseAfrica/Monrovia
's offset at the time was-00:44:30
, which doesn'tmatch
-00:45:00
. This in turn caused an error because Jiff's defaultbehavior is to reject parsed datetimes whose offset doesn't match a
valid offset in the corresponding time zone.
However, in this case, we want to accept it. What it comes down to
is that RFC 3339 and RFC 9557 do not support fractional minutes in
the offset. (I wonder why they flubbed that one.) So in order to
be compatible with existing implementations, Jiff serializes zoned
datetimes with fractional minutes by rounding to the nearest minute.
Hence why you might see
-00:45
. But this in turn means Jiff wouldn'tbe able to parse a zoned datetime that itself serialized. Which is sad.
So in learning from Temporal here, we permit offsets from tzdb that
have fractional minutes to be rounded to the nearest minute before
being compared with the parsed offset. In this case,
-00:44:30
getsrounded to
-00:45
and thus compares equal with the parsed offset.Note though that the offset of the parsed zoned datetime is still,
correctly,
-00:44:30
. It only becomes-00:45
when serializing viathe Temporal datetime printer. (One can print an offset with second
precision via the
%z
or%:z
strftime
conversion specifiers.)Ref tc39/proposal-temporal#3079
Fixes #231, Closes #233