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 (856787e) with master (3072a70)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (19d490d) during the generation of this report, so 3072a70 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

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

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