]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19634: time.strftime("%y") now raises a ValueError on AIX when given a
authorVictor Stinner <victor.stinner@gmail.com>
Sun, 17 Nov 2013 22:39:21 +0000 (23:39 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Sun, 17 Nov 2013 22:39:21 +0000 (23:39 +0100)
year before 1900.

Lib/test/test_strftime.py
Misc/NEWS
Modules/timemodule.c

index 61215a15ba36e0d7f07e93925879751b90e06c68..ff6274e8696acd0ddefa3f0b7d29ec76392fecff 100644 (file)
@@ -182,15 +182,13 @@ class Y1900Tests(unittest.TestCase):
     a date before 1900 is passed with a format string containing "%y"
     """
 
-    @unittest.skipUnless(sys.platform == "win32", "Only applies to Windows")
-    def test_y_before_1900_win(self):
-        with self.assertRaises(ValueError):
-            time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0))
-
-    @unittest.skipIf(sys.platform == "win32", "Doesn't apply on Windows")
-    def test_y_before_1900_nonwin(self):
-        self.assertEqual(
-            time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0)), "99")
+    def test_y_before_1900(self):
+        t = (1899, 1, 1, 0, 0, 0, 0, 0, 0)
+        if sys.platform == "win32" or sys.platform.startswith("aix"):
+            with self.assertRaises(ValueError):
+                time.strftime("%y", t)
+        else:
+            self.assertEqual(time.strftime("%y", t), "99")
 
     def test_y_1900(self):
         self.assertEqual(
index 58c3033719d35b321c4afab619d39702bdc4c5b0..74f58192248e243411051e39d28a2cf6a812648b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #19634: time.strftime("%y") now raises a ValueError on AIX when given a
+  year before 1900.
+
 - Fix test.support.bind_port() to not cause an error when Python was compiled
   on a system with SO_REUSEPORT defined in the headers but run on a system
   with an OS kernel that does not support that reasonably new socket option.
index 2e480071bc04b6dbe42baa82a07c3cf7fa89667a..32fe6a7c6903e912050dc786ebe8e2ed19fe6b17 100644 (file)
@@ -650,6 +650,20 @@ time_strftime(PyObject *self, PyObject *args)
             return NULL;
         }
     }
+#elif defined(_AIX)
+    for(outbuf = wcschr(fmt, '%');
+        outbuf != NULL;
+        outbuf = wcschr(outbuf+2, '%'))
+    {
+        /* Issue #19634: On AIX, wcsftime("y", (1899, 1, 1, 0, 0, 0, 0, 0, 0))
+           returns "0/" instead of "99" */
+        if (outbuf[1] == L'y' && buf.tm_year < 0) {
+            PyErr_SetString(PyExc_ValueError,
+                            "format %y requires year >= 1900 on AIX");
+            Py_DECREF(format);
+            return NULL;
+        }
+    }
 #endif
 
     fmtlen = time_strlen(fmt);