From 01bed651f652160e37e086f543da8c186fbe6d07 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 27 Jul 2024 13:58:20 -0400 Subject: [PATCH] Add test for TimeZoneInfo.tzname and fix bugs in the implementation. --- win32/Lib/win32timezone.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/win32/Lib/win32timezone.py b/win32/Lib/win32timezone.py index d5605a511..7e59df0b1 100644 --- a/win32/Lib/win32timezone.py +++ b/win32/Lib/win32timezone.py @@ -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: 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):