Skip to content

gh-148658: Fix DST timezone name for negative timestamps on Windows#148673

Open
jiekangtian wants to merge 4 commits intopython:mainfrom
jiekangtian:fix-gh-148658-dst-timezone
Open

gh-148658: Fix DST timezone name for negative timestamps on Windows#148673
jiekangtian wants to merge 4 commits intopython:mainfrom
jiekangtian:fix-gh-148658-dst-timezone

Conversation

@jiekangtian
Copy link
Copy Markdown

@jiekangtian jiekangtian commented Apr 17, 2026

Issue: #148658

Commit f5685a2 added _PyTime_windows_filetime() to support negative timestamps on Windows, but hardcoded tm_isdst = -1 (unknown) for local time. This caused strftime('%Z') to return the wrong timezone name.

For timezones that don't observe DST (checked via DaylightDate.wMonth == 0), set tm_isdst = 0 instead of -1 to ensure strftime('%Z') returns the standard time name.

…dows (python#148658)

Set tm_isdst to 0 for timezones that don't observe DST to ensure
strftime('%Z') returns the standard time name.
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 17, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 17, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@pganssle
Copy link
Copy Markdown
Member

Thanks for doing this. Can you either add a test or find a test that is currently disabled on Windows because it is failing because of this and enable it?

@jiekangtian
Copy link
Copy Markdown
Author

Thanks for doing this. Can you either add a test or find a test that is currently disabled on Windows because it is failing because of this and enable it?

Thanks for the reminder, Added the test. Verified it fails without the fix and passes with it.

@ynkdir
Copy link
Copy Markdown
Contributor

ynkdir commented Apr 17, 2026

DST name is still used for timezone which uses DST.

PS C:\Users\yukih\Downloads\cpython> tzutil.exe /s "Eastern Standard Time"   # set US timezone
PS C:\Users\yukih\Downloads\cpython> .\PCbuild\amd64\python.exe
Python 3.15.0a8+ (heads/fix-datetime-dirty:7398f51b3b3, Apr 17 2026, 21:22:52) [MSC v.1950 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>>
>>> datetime.fromtimestamp(-1).astimezone()
datetime.datetime(1969, 12, 31, 18, 59, 59, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=68400), 'Eastern Daylight Time'))
>>>
>>> datetime.fromtimestamp(0).astimezone()
datetime.datetime(1969, 12, 31, 19, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=68400), 'Eastern Standard Time'))

@jiekangtian jiekangtian force-pushed the fix-gh-148658-dst-timezone branch from 277267d to 1d0c65f Compare April 17, 2026 13:17
@jiekangtian
Copy link
Copy Markdown
Author

DST name is still used for timezone which uses DST.

PS C:\Users\yukih\Downloads\cpython> tzutil.exe /s "Eastern Standard Time"   # set US timezone
PS C:\Users\yukih\Downloads\cpython> .\PCbuild\amd64\python.exe
Python 3.15.0a8+ (heads/fix-datetime-dirty:7398f51b3b3, Apr 17 2026, 21:22:52) [MSC v.1950 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>>
>>> datetime.fromtimestamp(-1).astimezone()
datetime.datetime(1969, 12, 31, 18, 59, 59, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=68400), 'Eastern Daylight Time'))
>>>
>>> datetime.fromtimestamp(0).astimezone()
datetime.datetime(1969, 12, 31, 19, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=68400), 'Eastern Standard Time'))

Fixed. Improved handling for timezones that use DST.

@ynkdir
Copy link
Copy Markdown
Contributor

ynkdir commented Apr 17, 2026

That works fine for me. Thank you.

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.

3 participants