From 79ca4a4194b04f6ebf5ee7308970eeefd83d97b0 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 11 Aug 2003 07:19:06 +0000 Subject: Fix bug where handling issue of time.tzname[0] == time.tzname[1] and time.daylight were all true. Add an explicit test for this issue. Closes bug #783952 . --- Lib/_strptime.py | 10 +++++----- Lib/test/test_strptime.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Lib/_strptime.py b/Lib/_strptime.py index e906564..b3db42e 100644 --- a/Lib/_strptime.py +++ b/Lib/_strptime.py @@ -493,12 +493,12 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"): # Since -1 is default value only need to worry about setting tz if # it can be something other than -1. found_zone = found_dict['Z'].lower() - if locale_time.timezone[0] == locale_time.timezone[1] and \ - time.daylight: - pass #Deals with bad locale setup where timezone info is - # the same; first found on FreeBSD 4.4. - elif found_zone in ("utc", "gmt"): + if found_zone in ("utc", "gmt"): tz = 0 + elif time.tzname[0] == time.tzname[1] and \ + time.daylight: + continue #Deals with bad locale setup where timezone info is + # the same; first found on FreeBSD 4.4. elif locale_time.timezone[2].lower() == found_zone: tz = 0 elif time.daylight and \ diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py index ee24b72..919f741 100644 --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -319,6 +319,29 @@ class StrptimeTests(unittest.TestCase): "LocaleTime().timezone has duplicate values and " "time.daylight but timezone value not set to -1") + def test_bad_timezone(self): + # Explicitly test possibility of bad timezone; + # when time.tzname[0] == time.tzname[1] and time.daylight + if sys.platform == "mac": + return # MacOS9 has severely broken timezone support. + try: + original_tzname = time.tzname + original_daylight = time.daylight + time.tzname = ("PDT", "PDT") + time.daylight = 1 + # Need to make sure that timezone is not calculated since that + # calls time.tzset and overrides temporary changes to time . + _strptime._locale_cache = _strptime.TimeRE(_strptime.LocaleTime( + timezone=("PDT", "PDT"))) + _strptime._regex_cache.clear() + tz_value = _strptime.strptime("PDT", "%Z")[8] + self.failUnlessEqual(tz_value, -1) + finally: + time.tzname = original_tzname + time.daylight = original_daylight + _strptime._locale_cache = _strptime.TimeRE() + _strptime._regex_cache.clear() + def test_date_time(self): # Test %c directive for position in range(6): -- cgit v0.12