Repository navigation
Conversation
format_interval() raises NotImplementedError for any skeleton whose CLDR
interval pattern defines the era ('G') or day period ('B') field, because
DateTimeFormat.extract() only understood y M d H h m a. The affected
skeletons (Gy, GyM, GyMd, GyMEd, GyMMM, GyMMMd, GyMMMEd, GyMMMM,
GyMMMMd, GyMMMMEd, GyMMMEEEEd, Bh, Bhm) are defined in interval_formats
for every locale, so format_interval(datetime(2020, 1, 1),
datetime(2021, 1, 1), 'Gy', locale='en') failed with
"Not implemented: extracting 'G' ...".
Extract those two fields, mirroring how they are rendered: the era index
from format_era() and the day period identifier from format_period().
Sweeping all locales, interval skeletons and instants (230,698 cases)
shows 20,220 NotImplementedError crashes on the base, 0 after the fix,
with no case that previously produced output changing its output.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
format_interval()raisedNotImplementedErrorfor every skeleton whose CLDR interval pattern defines the era (G) or the day period (B), becauseDateTimeFormat.extract()only understoody M d H h m a:interval_formatsdefines those fields for every locale, so 13 skeletons are affected everywhere —Gy,GyM,GyMd,GyMEd,GyMMM,GyMMMd,GyMMMEd,GyMMMM,GyMMMMd,GyMMMMEd,GyMMMEEEEd,BhandBhm— 1,121 locales in all.This extracts the two fields the same way they are rendered: the era index as
format_era()computes it, and the day-period identifier fromformat_period(). The return annotation widens toint | str, matching the existingacase, and the value picked is the one for the field the two instants differ in, so the output follows the CLDR pattern selected for it:A sweep over all locales, all interval skeletons and a set of instants (230,698 cases) goes from 20,220
NotImplementedErrors to none, with 20,132 of those cases returning output instead of raising and no case whose output changed — nothing that used to succeed formats differently now.tests/test_date_intervals.py::test_format_interval_era_and_day_periodcovers the four skeletons above: 4 failed before, 14 passed after in that file. The full suite is 1 failed / 7,831 passed with the change (the remaining failure,test_setuptools_commands, is environment-only and fails on the default branch too).