]> granicus.if.org Git - python/commitdiff
Merged revisions 75011 via svnmerge from
authorBrett Cannon <bcannon@gmail.com>
Tue, 22 Sep 2009 00:32:59 +0000 (00:32 +0000)
committerBrett Cannon <bcannon@gmail.com>
Tue, 22 Sep 2009 00:32:59 +0000 (00:32 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75011 | brett.cannon | 2009-09-21 17:29:48 -0700 (Mon, 21 Sep 2009) | 10 lines

  When range checking was added to time.strftime() a check was placed on tm_isdst
  to make sure it fell within [-1, 1] just in case someone implementing
  strftime() in libc was stupid enough to assume this. Turns out, though, some
  OSs (e.g. zOS) are stupid enough to use values outside of this range for time
  structs created by the system itself. So instead of throwing a ValueError,
  tm_isdst is now normalized before being passed to strftime().

  Fixes issue #6823. Thanks Robert Shapiro for diagnosing the problem and
  contributing an initial patch.
........

Lib/test/test_time.py
Misc/ACKS
Modules/timemodule.c

index 49a9d17710dfd49644b48f574ac559b88ba4d8dc..4ce90e967a403ad62c31425b8885ad615cad26e0 100644 (file)
@@ -87,11 +87,6 @@ class TimeTestCase(unittest.TestCase):
                             (1900, 1, 1, 0, 0, 0, 0, -1, -1))
         self.assertRaises(ValueError, time.strftime, '',
                             (1900, 1, 1, 0, 0, 0, 0, 367, -1))
-        # Check daylight savings flag [-1, 1]
-        self.assertRaises(ValueError, time.strftime, '',
-                            (1900, 1, 1, 0, 0, 0, 0, 1, -2))
-        self.assertRaises(ValueError, time.strftime, '',
-                            (1900, 1, 1, 0, 0, 0, 0, 1, 2))
 
     def test_default_values_for_zero(self):
         # Make sure that using all zeros uses the proper default values.
index b2ada2bdca5b8ae10f389b59a984781b7f0ed598..d419b7e2e600829e5a60dca7bb8328430cbed968 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -674,6 +674,7 @@ Jerry Seutter
 Denis Severson
 Ian Seyer
 Ha Shao
+Richard Shapiro
 Bruce Sherwood
 Pete Shinners
 Michael Shiplett
index d8db4095701bcbc29aa6473c58fd4cfeadc47f6e..af0e1a7759b981fec43ebab7aa2d0ce83929f1f5 100644 (file)
@@ -512,11 +512,13 @@ time_strftime(PyObject *self, PyObject *args)
             PyErr_SetString(PyExc_ValueError, "day of year out of range");
             return NULL;
         }
-        if (buf.tm_isdst < -1 || buf.tm_isdst > 1) {
-            PyErr_SetString(PyExc_ValueError,
-                            "daylight savings flag out of range");
-            return NULL;
-        }
+       /* Normalize tm_isdst just in case someone foolishly implements %Z
+          based on the assumption that tm_isdst falls within the range of
+          [-1, 1] */
+        if (buf.tm_isdst < -1)
+           buf.tm_isdst = -1;
+       else if (buf.tm_isdst > 1)
+           buf.tm_isdst = 1;
 
 #ifdef HAVE_WCSFTIME
        tmpfmt = PyBytes_FromStringAndSize(NULL,