]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fixes bug of timezone value being left as -1 when ``time.tzname[0] ==
authorBrett Cannon <bcannon@gmail.com>
Thu, 3 Jul 2003 19:59:57 +0000 (19:59 +0000)
committerBrett Cannon <bcannon@gmail.com>
Thu, 3 Jul 2003 19:59:57 +0000 (19:59 +0000)
time.tzname[1] and not time.daylight`` is true when it should only when
time.daylight is true.  Tests are also fixed.

Closes bug #763047 and its cohort #763052.

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

index dcc447be5f9aaa7932c930665b340efec420d49f..ba9dde09972aff5f31991e7ef7a0e8dee39f3072 100644 (file)
@@ -501,16 +501,17 @@ 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]:
+            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"):
                 tz = 0
             elif locale_time.timezone[2].lower() == found_zone:
                 tz = 0
-            elif time.daylight:
-                if locale_time.timezone[3].lower() == found_zone:
-                    tz = 1
+            elif time.daylight and \
+                locale_time.timezone[3].lower() == found_zone:
+                tz = 1
 
     # Cannot pre-calculate datetime_date() since can change in Julian
     #calculation and thus could have different value for the day of the week
index 2966e22a5c8c73946c0abb5d04c7ae90f2025ae6..dcde2c3c873e2169cad8351e484341b46621f339 100644 (file)
@@ -303,14 +303,14 @@ class StrptimeTests(unittest.TestCase):
         strf_output = time.strftime("%Z")  #UTC does not have a timezone
         strp_output = _strptime.strptime(strf_output, "%Z")
         locale_time = _strptime.LocaleTime()
-        if time.tzname[0] != time.tzname[1]:
+        if time.tzname[0] != time.tzname[1] or not time.daylight:
             self.failUnless(strp_output[8] == time_tuple[8],
                             "timezone check failed; '%s' -> %s != %s" %
                              (strf_output, strp_output[8], time_tuple[8]))
         else:
             self.failUnless(strp_output[8] == -1,
-                            "LocaleTime().timezone has duplicate values but "
-                             "timezone value not set to -1")
+                            "LocaleTime().timezone has duplicate values and "
+                             "time.daylight but timezone value not set to -1")
 
     def test_date_time(self):
         # Test %c directive