Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in TimeZoneInfo.tzname #2337

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions win32/Lib/win32timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,27 @@ def __str__(self):
return self.displayName

def tzname(self, dt):
winInfo = self.getWinInfo(dt)
if self.dst(dt) == winInfo.daylight_bias:
"""
>>> MST = TimeZoneInfo('Mountain Standard Time')
>>> MST.tzname(datetime.datetime(2003, 8, 2))
'Mountain Daylight Time'
>>> MST.tzname(datetime.datetime(2003, 11, 25))
'Mountain Standard Time'
"""

winInfo = self.getWinInfo(dt.year)
if self.dst(dt) == -winInfo.daylight_bias:
Copy link
Collaborator

@Avasam Avasam Jul 28, 2024

Choose a reason for hiding this comment

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

I just noticed, but probably better not to repeat self.dst call up to 3 times.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm a little reluctant to spend energy optimizing a function that's never been used. It's also unnecessary to address this bugfix. Let's leave it for another contrib (be my guest).

result = self.daylightName
elif self.dst(dt) == winInfo.standard_bias:
elif self.dst(dt) == -winInfo.standard_bias:
result = self.standardName
else:
raise ValueError(
"Unexpected daylight bias",
dt,
self.dst(dt),
winInfo.daylight_bias,
winInfo.standard_bias,
)
return result

def getWinInfo(self, targetYear):
Expand Down
Loading