Skip to content

Display seconds in GMT offsets if available - #1461

Open
tomasr8 wants to merge 1 commit into
python-babel:masterfrom
tomasr8:zone-offset-seconds
Open

tomasr8 wants to merge 1 commit into
python-babel:masterfrom
tomasr8:zone-offset-seconds

Conversation

@tomasr8

@tomasr8 tomasr8 commented Nov 12, 2026

Copy link
Copy Markdown
Member

I noticed this while working on the skeleton matching.

Per the spec, the localized GMT format includes seconds when applicable, which we currently ignore:

The long format always uses 2-digit hours field and minutes field, with optional 2-digit seconds field. The short format is intended for the shortest representation and uses hour fields without leading zero, with optional 2-digit minutes and seconds fields.

There are real (albeit historic) timezones with sub-minute offsets, e.g. Africa/Monrovia before 1972:

>>> from datetime import datetime
>>> from zoneinfo import ZoneInfo
>>> dt = datetime(1970, 1, 1)
>>> ZoneInfo('Africa/Monrovia').utcoffset(dt)
datetime.timedelta(days=-1, seconds=83730)

I suggest we make get_timezone_gmt display seconds when applicable

Comment thread babel/dates.py
else:
pattern = locale.zone_formats['gmt_utc' if utc else 'gmt'] % '%s%02d:%02d'
return pattern % (sign, hours, seconds // 60)
# The long format shows seconds if the zone offset has any

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The short localized format does that too, but we don't support it (we only support ISO short). I'd like to add it in a follow up.

@codspeed

codspeed Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing tomasr8:zone-offset-seconds (ae7afad) with master (9214841)

Open in CodSpeed

@tomasr8
tomasr8 force-pushed the zone-offset-seconds branch from 138e20d to 856787e Compare November 12, 2026 21:10
@tomasr8
tomasr8 force-pushed the zone-offset-seconds branch from 856787e to ae7afad Compare November 14, 2026 18:50
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.68%. Comparing base (9214841) to head (ae7afad).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1461   +/-   ##
=======================================
  Coverage   93.67%   93.68%           
=======================================
  Files          27       27           
  Lines        4983     4987    +4     
=======================================
+ Hits         4668     4672    +4     
  Misses        315      315           
Flag Coverage Δ
macos-26-3.10 92.76% <100.00%> (+<0.01%) ⬆️
macos-26-3.11 92.70% <100.00%> (+<0.01%) ⬆️
macos-26-3.12 92.96% <100.00%> (+<0.01%) ⬆️
macos-26-3.13 92.96% <100.00%> (+<0.01%) ⬆️
macos-26-3.14 92.94% <100.00%> (+<0.01%) ⬆️
macos-26-3.15 92.94% <100.00%> (+<0.01%) ⬆️
macos-26-3.9 92.69% <100.00%> (+<0.01%) ⬆️
macos-26-pypy3.10 92.76% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.10 92.78% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.11 92.72% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.12 92.98% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.13 92.98% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.14 92.96% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.15 92.96% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.9 92.71% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-pypy3.10 92.78% <100.00%> (+<0.01%) ⬆️
windows-2025-3.10 92.77% <100.00%> (+<0.01%) ⬆️
windows-2025-3.11 92.71% <100.00%> (+<0.01%) ⬆️
windows-2025-3.12 92.97% <100.00%> (+<0.01%) ⬆️
windows-2025-3.13 92.97% <100.00%> (+<0.01%) ⬆️
windows-2025-3.14 92.95% <100.00%> (+<0.01%) ⬆️
windows-2025-3.15 92.95% <100.00%> (+<0.01%) ⬆️
windows-2025-3.9 92.70% <100.00%> (+<0.01%) ⬆️
windows-2025-pypy3.10 92.77% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant