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.
22 locales (az_Arab, en_Dsrt, en_Shaw and their variants) carry no names for the flexible day periods that a 'B' or 'b' pattern element asks for -- they only have 'am' and 'pm' -- so format_datetime() raised ValueError: Could not format period morning2 in az_Arab for a valid locale and a valid pattern. CLDR resolves a flexible day period that has no name to the day period containing the time, and a missing stand-alone name to the format name; do the same here, and keep raising only when neither has a name.
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.
22 locales (
az_Arab,en_Dsrt,en_Shawand their country variants) have no names for the flexible day periods that aBorbpattern element asks for — their period data contains onlyamandpm— so formatting a valid pattern in a valid locale raised:DateTimeFormat.format_period()looked for the flexible period name (morning2) in up to four widths and gave up, even though the locale does name the day period that time belongs to. CLDR resolves a flexible day period with no name of its own to the day period containing the time, and a missing stand-alone name to the format name; the method now does the same, and still raises when neither has a name. Locales that do carry flexible names are unaffected:format_datetime(dt, 'B', locale='fi_FI')is stillaamup.and the examples in the method's docstring are unchanged.tests/test_dates.py::test_format_period_without_names_for_the_flexible_day_periodfails on the default branch withValueError: Could not format period morning2and passes with the change; the wholetest_dates.pyis 2385 passed / 2 xfailed, andruff checkreports no findings.Prepared with AI assistance; every line was verified by running the cases above.