Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55329f8

Browse files
committed
Issue #19634: time.strftime("%y") now raises a ValueError on AIX when given a
year before 1900.
1 parent b6e622d commit 55329f8

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

Lib/test/test_strftime.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,13 @@ class Y1900Tests(unittest.TestCase):
182182
a date before 1900 is passed with a format string containing "%y"
183183
"""
184184

185-
@unittest.skipUnless(sys.platform == "win32", "Only applies to Windows")
186-
def test_y_before_1900_win(self):
187-
with self.assertRaises(ValueError):
188-
time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0))
189-
190-
@unittest.skipIf(sys.platform == "win32", "Doesn't apply on Windows")
191-
def test_y_before_1900_nonwin(self):
192-
self.assertEqual(
193-
time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0)), "99")
185+
def test_y_before_1900(self):
186+
t = (1899, 1, 1, 0, 0, 0, 0, 0, 0)
187+
if sys.platform == "win32" or sys.platform.startswith("aix"):
188+
with self.assertRaises(ValueError):
189+
time.strftime("%y", t)
190+
else:
191+
self.assertEqual(time.strftime("%y", t), "99")
194192

195193
def test_y_1900(self):
196194
self.assertEqual(

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Core and Builtins
5050
Library
5151
-------
5252

53+
- Issue #19634: time.strftime("%y") now raises a ValueError on AIX when given a
54+
year before 1900.
55+
5356
- Fix test.support.bind_port() to not cause an error when Python was compiled
5457
on a system with SO_REUSEPORT defined in the headers but run on a system
5558
with an OS kernel that does not support that reasonably new socket option.

Modules/timemodule.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,20 @@ time_strftime(PyObject *self, PyObject *args)
650650
return NULL;
651651
}
652652
}
653+
#elif defined(_AIX)
654+
for(outbuf = wcschr(fmt, '%');
655+
outbuf != NULL;
656+
outbuf = wcschr(outbuf+2, '%'))
657+
{
658+
/* Issue #19634: On AIX, wcsftime("y", (1899, 1, 1, 0, 0, 0, 0, 0, 0))
659+
returns "0/" instead of "99" */
660+
if (outbuf[1] == L'y' && buf.tm_year < 0) {
661+
PyErr_SetString(PyExc_ValueError,
662+
"format %y requires year >= 1900 on AIX");
663+
Py_DECREF(format);
664+
return NULL;
665+
}
666+
}
653667
#endif
654668

655669
fmtlen = time_strlen(fmt);

0 commit comments

Comments
 (0)