diff -r 2de806c8b070 Lib/test/test_strftime.py --- a/Lib/test/test_strftime.py Wed Nov 06 22:17:39 2013 +1000 +++ b/Lib/test/test_strftime.py Wed Nov 06 14:58:58 2013 +0000 @@ -177,5 +177,23 @@ print(" Expected %s, but got %s" % (e[1], result)) +@unittest.skipUnless(sys.platform == "win32", "Only applies to Windows") +class WindowsTests(unittest.TestCase): + """A limitation of the MS C runtime library is that it crashes if + a date before 1900 is passed with a format string containing "%y" + """ + + def test_y_before_1900(self): + with self.assertRaises(ValueError): + time.strftime("%y", (1899, 1, 1, 0, 0, 0, 0, 0, 0)) + + def test_y_1900(self): + self.assertEquals( + time.strftime("%y", (1900, 1, 1, 0, 0, 0, 0, 0, 0)), "00") + + def test_y_after_1900(self): + self.assertEquals( + time.strftime("%y", (2013, 1, 1, 0, 0, 0, 0, 0, 0)), "13") + if __name__ == '__main__': unittest.main() diff -r 2de806c8b070 Modules/timemodule.c --- a/Modules/timemodule.c Wed Nov 06 22:17:39 2013 +1000 +++ b/Modules/timemodule.c Wed Nov 06 14:58:58 2013 +0000 @@ -642,6 +642,13 @@ Py_DECREF(format); return NULL; } + if (strchr("y", outbuf[1]) && buf.tm_year < 0) + { + PyErr_SetString(PyExc_ValueError, + "format %y requires year >= 1900 on Windows"); + Py_DECREF(format); + return NULL; + } } #endif