Commit b55de367 authored by Victor Stinner's avatar Victor Stinner

Issue #19634: time.strftime("%y") now raises a ValueError on AIX when given a

year before 1900.
parent 7548040d
...@@ -182,15 +182,13 @@ class Y1900Tests(unittest.TestCase): ...@@ -182,15 +182,13 @@ class Y1900Tests(unittest.TestCase):
a date before 1900 is passed with a format string containing "%y" 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(self):
def test_y_before_1900_win(self): t = (1899, 1, 1, 0, 0, 0, 0, 0, 0)
with self.assertRaises(ValueError): if sys.platform == "win32" or sys.platform.startswith("aix"):
time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0)) with self.assertRaises(ValueError):
time.strftime("%y", t)
@unittest.skipIf(sys.platform == "win32", "Doesn't apply on Windows") else:
def test_y_before_1900_nonwin(self): self.assertEqual(time.strftime("%y", t), "99")
self.assertEqual(
time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0)), "99")
def test_y_1900(self): def test_y_1900(self):
self.assertEqual( self.assertEqual(
......
...@@ -50,6 +50,9 @@ Core and Builtins ...@@ -50,6 +50,9 @@ Core and Builtins
Library 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 - 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 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. with an OS kernel that does not support that reasonably new socket option.
......
...@@ -650,6 +650,20 @@ time_strftime(PyObject *self, PyObject *args) ...@@ -650,6 +650,20 @@ time_strftime(PyObject *self, PyObject *args)
return NULL; 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 #endif
fmtlen = time_strlen(fmt); fmtlen = time_strlen(fmt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment