gh-148658: Fix DST timezone name for negative timestamps on Windows#148673
gh-148658: Fix DST timezone name for negative timestamps on Windows#148673jiekangtian wants to merge 4 commits intopython:mainfrom
Conversation
…dows (python#148658) Set tm_isdst to 0 for timezones that don't observe DST to ensure strftime('%Z') returns the standard time name.
|
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 |
|
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. |
|
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')) |
277267d to
1d0c65f
Compare
Fixed. Improved handling for timezones that use DST. |
|
That works fine for me. Thank you. |
Issue: #148658
Commit f5685a2 added
_PyTime_windows_filetime()to support negative timestamps on Windows, but hardcodedtm_isdst = -1(unknown) for local time. This causedstrftime('%Z')to return the wrong timezone name.For timezones that don't observe DST (checked via
DaylightDate.wMonth == 0), settm_isdst = 0instead of-1to ensurestrftime('%Z')returns the standard time name.