Repository navigation
Fix format_interval fallback ignoring the requested skeleton - #1524
Open
Yasser-Ameur wants to merge 1 commit into
Open
Yasser-Ameur wants to merge 1 commit into
Yasser-Ameur wants to merge 1 commit into
Conversation
When no interval format matches the skeleton, format_interval formats both ends and joins them with the locale's interval fallback pattern. The ends were formatted with the default date or time format instead of the requested skeleton, so format_interval(t1, t2, "Hms", locale="en") printed AM/PM although "Hms" is a 24-hour skeleton. _format_fallback_interval has a "Use the given skeleton" branch for this, added together with format_interval in 796c3d2. It became unreachable from this path in cd70395 (both part of python-babel#316), when the fuzzy match started overwriting `skeleton` before the fallback call: the value is None when nothing matched, and always None with fuzzy=False. Keep the requested skeleton in its own variable and pass that to the fallback. Skeletons that have interval data, skeleton=None and unknown skeletons behave as before.
Yasser-Ameur
marked this pull request as ready for review
December 1, 2026 00:03
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_intervalignores the requested skeleton when the locale has no interval format for it. The two ends are formatted with the locale's default format, so a 24 hour skeleton prints AM and PM in English:With two datetimes on the same day,
"Hms"gaveJan 8, 2016, 9:00:00 AM – Jan 8, 2016, 9:00:00 PMwhere09:00:00 – 21:00:00was asked for.Cause
_format_fallback_intervalalready formats both ends with the skeleton when that skeleton is inlocale.datetime_skeletons, and falls back to the default format otherwise. Butformat_intervalreuses theskeletonvariable for its lookup inlocale.interval_formats: when nothing matches, the variable has been set toNoneby the time the fallback is called, so the branch that uses the requested skeleton never ran. Both pieces come from #316.Change
format_intervalkeeps the skeleton it was called with and passes that one to_format_fallback_interval. Skeletons that have an interval format, andskeleton=None, give the same output as before.Tests
tests/test_date_intervals.pygets tests for the fallback with a requested skeleton (times and datetimes, with and withoutfuzzy), forskeleton=None, and for a skeleton that has an interval format. The first group fails on master.Run locally on Python 3.14 after
make import-cldr:tests/test_date_intervals.pyandtests/test_dates.pygive 2593 passed, 2 xfailed, andruff checkis clean on the two changed files.