]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix bug where handling issue of time.tzname[0] == time.tzname[1] and
authorBrett Cannon <bcannon@gmail.com>
Mon, 11 Aug 2003 07:19:06 +0000 (07:19 +0000)
committerBrett Cannon <bcannon@gmail.com>
Mon, 11 Aug 2003 07:19:06 +0000 (07:19 +0000)
time.daylight were all true.  Add an explicit test for this issue.

Closes bug #783952 .

Lib/_strptime.py
Lib/test/test_strptime.py

index e9065649925f4e7ebcc7b2b790c02c4d558c8469..b3db42e0f69af298d9fc6e65373e825681b84fc1 100644 (file)
@@ -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 \
index ee24b72fbb78349a2c1e11080addd9f50d897b26..919f7416e8e422ff111f739552554cadf937a223 100644 (file)
@@ -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):