Skip to content

gh-161194: Use libc timezone variables for time module constants - #161338

Open
nascheme wants to merge 3 commits into
python:mainfrom
nascheme:gh-161194-tz-libc-globals
Open

nascheme wants to merge 3 commits into
python:mainfrom
nascheme:gh-161194-tz-libc-globals

Conversation

@nascheme

@nascheme nascheme commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Previously the libc path in init_timezone() was gated on HAVE_DECL_TZNAME, which configure only defines when struct tm lacks tm_zone. On Linux and macOS this meant timezone, altzone, daylight and tzname were guessed by sampling localtime() near January 1 and July 1 of the current year. That gives stale values when a zone's rules change mid-year (e.g. America/Vancouver moving to permanent MST on 2026-11-01) and wrong standard/DST names for negative DST zones.

Add a configure check, HAVE_TIMEZONE_GLOBALS, that verifies timezone, daylight and tzname are usable as variables, and use libc's values whenever it is defined. FreeBSD, where timezone is a function, keeps the sampling fallback. When libc has no altzone, use timezone - 3600 only if daylight is set, otherwise timezone.

Note: creation of this PR was assisted by an LLM.

Previously the libc path in init_timezone() was gated on
HAVE_DECL_TZNAME, which configure only defines when struct tm lacks
tm_zone.  On Linux and macOS this meant timezone, altzone, daylight and
tzname were guessed by sampling localtime() near January 1 and July 1
of the current year.  That gives stale values when a zone's rules
change mid-year (e.g. America/Vancouver moving to permanent MST on
2026-11-01) and wrong standard/DST names for negative DST zones.

Add a configure check, HAVE_TIMEZONE_GLOBALS, that verifies timezone,
daylight and tzname are usable as variables, and use libc's values
whenever it is defined.  FreeBSD, where timezone is a function, keeps
the sampling fallback.  When libc has no altzone, use timezone - 3600
only if daylight is set, otherwise timezone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant