Repository navigation
Conversation
Muguett-DBY
reviewed
Nov 20, 2026
Muguett-DBY
left a comment
There was a problem hiding this comment.
One historical offset case for the new O formatter.
| seconds = offset.days * 24 * 60 * 60 + offset.seconds | ||
| sign = '-' if seconds < 0 else '+' | ||
| hours, seconds = divmod(abs(seconds), 3600) | ||
| minutes = seconds // 60 |
There was a problem hiding this comment.
Could this keep the seconds when the offset has them? A datetime with timezone(timedelta(minutes=9, seconds=21)) gives GMT+0:09 with O and en_US on this branch. That's the historical Paris offset, and ICU's shortOffset gives GMT+0:09:21 for Paris in 1890.
minutes, seconds = divmod(seconds, 60) would let this keep the seconds while leaving the whole-minute output alone. UTS #35, localized GMT format
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.
Fixes #1478.
Problem
A date pattern with a single
O(short localized GMT format, e.g.GMT-8) printed the stringNone, becauseDateTimeFormat.format_timezoneonly implementedOOOOand fell through forO:1(there was a# TODO: To add support for O:1marker).PATTERN_CHARSacceptsOwith count 1, so the pattern validated fine and theNonesilently ended up in the output.Solution
_get_timezone_gmt_short()helper that formats the UTC offset per UTS python-format flag incorrectly forced on all extractors #35 forO: hours without a leading zero, minutes only when nonzero (GMT-8,GMT+5:30,GMT+0for UTC), wrapped in the locale's GMT format (UTC-8in French).format_timezonenow uses it forO:1;OOOObehavior is unchanged.Note: this adds the short-GMT helper independently of #1284 (open since June, which adds a helper with the same name and semantics for the
zfallback). The two should be easy to unify if that PR moves forward.Verification
make import-cldr(CLDR 49)python -X utf8 -m pytest tests/test_dates.py -q→ 2575 passed, 2 xfailedpython -X utf8 -m pytest -q(full suite) → 8222 passed, 3 skipped, 2 xfailedruff check babel/dates.py tests/test_dates.py→ cleanNew/extended tests cover
Ofor Los Angeles (GMT-8), UTC (GMT+0), Kolkata (GMT+5:30), and the localized French GMT format (UTC-8), exercised through both thepytzandzoneinfofixtures.