Skip to content

Fix local timezone offsets in get_timezone_name(None) - #1356

Open
arindamsikder wants to merge 1 commit into
python-babel:masterfrom
arindamsikder:fix/local-timezone-name-offset
Open

arindamsikder wants to merge 1 commit into
python-babel:masterfrom
arindamsikder:fix/local-timezone-name-offset

Conversation

@arindamsikder

Copy link
Copy Markdown

Summary

Preserve the local timezone when resolving get_timezone_name(None), including its GMT-offset fallback and daylight-saving-time selection.

Problem

The None path creates a naive local datetime. If there is no translated timezone name, get_timezone_gmt() treats that datetime as UTC, so a local offset such as GMT+05:30 becomes GMT+00:00. This causes the existing test_get_timezone_name_misc regression to fail outside UTC.

Solution

  • Construct the current datetime with LOCALTZ attached through datetime.now(LOCALTZ).
  • Read DST from the resulting datetime rather than asking the original timezone object to localize it again. This also handles pytz's localized timezone objects.
  • Correct the None parameter documentation to reflect the established local-time behavior.
  • Add deterministic positive/negative fixed-offset and winter/summer regression coverage for pytz and zoneinfo.

No timezone database, public API, dependency, or workflow changes.

Testing

Executed on Linux/Python 3.11 in a credential-free, network-isolated Bubblewrap environment:

  • New regression tests on the unchanged base: 6 failed for the expected incorrect offset/naive datetime behavior; the same tests pass with the fix.
  • TZ=UTC make test PYTEST_FLAGS='-p no:cacheprovider --basetemp=/tmp/pytest': 7,837 passed, 7 skipped, 2 xfailed. One existing pytest deprecation warning remains.
  • tests/test_dates.py under both UTC and Asia/Kolkata: 2,390 passed, 2 xfailed in each run.
  • Independent read-only automated review reran the dates, date/time formatting, intervals, support-formatting and localtime suites under UTC, America/New_York and Asia/Kolkata: 2,457 passed, 2 xfailed in each run.
  • Independent zoneinfo-only runs (pytz imports disabled) under UTC and America/New_York: 1,289 passed, 1,169 skipped, 1 xfailed in each run.
  • Additional independent probes exercised named/fixed zones, DST transitions, positive/negative offsets, explicit and generic inputs, widths, zone variants and return_zone; no compatibility regression was found.
  • Pinned Ruff 0.14.10: ruff check --no-cache babel/dates.py tests/test_dates.py passed.
  • git diff --check passed.

The full supported-Python/OS CI matrix was not run locally; upstream CI and maintainer review are still required.

Related Issue

Fixes #935.

Automation disclosure

Prepared by the Hermes autonomous engineering agent operated by Arindam Sikder (@arindamsikder), with a separate read-only automated reviewer that independently executed tests against the exact patch. This is not a claim of human maintainer approval. No automatic merge is requested or performed.

Base: e2a17919f0eb988bfea2883b00793ca4d5d37c4f
Head: 5a68e8668b6e549a3f2e6571838455978f453ef2

Comment thread babel/dates.py
resulting display name will be generic, i.e.
independent of daylight savings time; if `None`, the
current date in UTC is assumed
current date and time in the local timezone is assumed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a behavioral change, isn't it?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_get_timezone_name_misc fails when system TZ isn't UTC

2 participants