]> granicus.if.org Git - python/commitdiff
When range checking was added to time.strftime() a check was placed on tm_isdst
authorBrett Cannon <bcannon@gmail.com>
Tue, 22 Sep 2009 00:29:48 +0000 (00:29 +0000)
committerBrett Cannon <bcannon@gmail.com>
Tue, 22 Sep 2009 00:29:48 +0000 (00:29 +0000)
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
Misc/NEWS
Modules/timemodule.c

index 965f7e2fef301f59a6982a9d6960d504beea50c2..6683de6ea204b4eacccb26c8554353b66e37f264 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 e0bd435005a61f36560aef91dfe81547a2cb9e98..4889be8aeece15a2e491fb0a41e013dd96dc31a8 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -669,6 +669,7 @@ Jerry Seutter
 Denis Severson
 Ian Seyer
 Ha Shao
+Richard Shapiro
 Bruce Sherwood
 Pete Shinners
 Michael Shiplett
index 89cbf3ca460931338eb3dc244ead5c4e0e3cac9f..15db19963ec3354ae0b7d06edcd3d368c55f61c9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1340,6 +1340,10 @@ C-API
 Extension Modules
 -----------------
 
+- Issue #6823: Allow time.strftime() to accept a tuple with a isdst field
+  outside of the range of [-1, 1] by normalizing the value to within that
+  range.
+
 - Issue #6877: Make it possible to link the readline extension to libedit
   on OSX.
 
index 2f4092d64e184e65349d3f948ee390cd2aa65a41..624405eb378f6f4da6851209d3d14907b5321313 100644 (file)
@@ -464,11 +464,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 MS_WINDOWS
        /* check that the format string contains only valid directives */