Skip to content

Honor timezone offsets in datetime_to_header - #484

Closed
pacocartones wants to merge 1 commit into
psf:masterfrom
pacocartones:fix/header-timezone-offset
Closed

pacocartones wants to merge 1 commit into
psf:masterfrom
pacocartones:fix/header-timezone-offset

Conversation

@pacocartones

@pacocartones pacocartones commented Oct 20, 2026 •

Copy link
Copy Markdown

datetime_to_header() currently treats the wall-clock fields of an aware datetime as UTC. For example, 12:00 at UTC+02 is formatted as 12:00 UTC rather than 10:00 UTC.

Use utctimetuple() before calendar.timegm() to honor the offset. Preserve existing output for UTC and naive datetimes. Tests cover positive and negative half-hour offsets crossing calendar days, UTC, and naive inputs.

Scope: built-in callers already supply UTC datetimes, so their behavior is unchanged. This fixes direct use of the module helper, including custom heuristics supplying an aware non-UTC datetime. It is not a fix for the normal built-in expiry path or all timezone-related caching behavior.

Validation on Python 3.12 in WSL:

  • Two new offset regressions fail on the unchanged base; two compatibility controls pass.
  • All four focal tests pass with the patch.
  • Ruff formatting and git diff --check pass; tests lint clean. Source UP035/RUF012 findings also exist on the unchanged base.

The focal harness loads the complete real heuristics module with importlib and extracts only the new test class via AST to avoid unavailable requests/server test dependencies. The full heuristics/package suites and other Python versions were not run. No dependencies were installed.

@woodruffw woodruffw closed this Oct 20, 2026
@psf psf locked as spam and limited conversation to collaborators Oct 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants