# HG changeset patch # Parent 89821243621b2ebf7aa38143e813c2cc76739fff diff -r 89821243621b Lib/test/test_time.py --- a/Lib/test/test_time.py Thu Jul 14 07:45:24 2016 +0300 +++ b/Lib/test/test_time.py Thu Jul 14 05:27:23 2016 +0000 @@ -523,6 +523,7 @@ class _TestAsctimeYear: _format = '%d' + MINYEAR = TIME_MINYEAR def yearstr(self, y): return time.asctime((y,) + (0,) * 8).split()[-1] @@ -543,6 +544,7 @@ _format = '%04d' else: _format = '%d' + MINYEAR = TIME_MINYEAR + 1900 def yearstr(self, y): return time.strftime('%Y', (y,) + (0,) * 8) @@ -604,10 +606,7 @@ self.assertEqual(self.yearstr(-123456789), str(-123456789)) self.assertEqual(self.yearstr(-1234567890), str(-1234567890)) self.assertEqual(self.yearstr(TIME_MINYEAR + 1900), str(TIME_MINYEAR + 1900)) - # Issue #13312: it may return wrong value for year < TIME_MINYEAR + 1900 - # Skip the value test, but check that no error is raised - self.yearstr(TIME_MINYEAR) - # self.assertEqual(self.yearstr(TIME_MINYEAR), str(TIME_MINYEAR)) + self.assertEqual(self.yearstr(self.MINYEAR), str(self.MINYEAR)) self.assertRaises(OverflowError, self.yearstr, TIME_MINYEAR - 1) diff -r 89821243621b Modules/timemodule.c --- a/Modules/timemodule.c Thu Jul 14 07:45:24 2016 +0300 +++ b/Modules/timemodule.c Thu Jul 14 05:27:23 2016 +0000 @@ -405,7 +405,7 @@ * an exception and return 0 on error. */ static int -gettmarg(PyObject *args, struct tm *p) +gettmarg(PyObject *args, struct tm *p, int tm_year_zero) { int y; @@ -422,7 +422,7 @@ &p->tm_hour, &p->tm_min, &p->tm_sec, &p->tm_wday, &p->tm_yday, &p->tm_isdst)) return 0; - p->tm_year = y - 1900; + p->tm_year = y - tm_year_zero; p->tm_mon--; p->tm_wday = (p->tm_wday + 1) % 7; p->tm_yday--; @@ -576,7 +576,7 @@ if (pylocaltime(&tt, &buf) == -1) return NULL; } - else if (!gettmarg(tup, &buf) || !checktm(&buf)) + else if (!gettmarg(tup, &buf, 1900) || !checktm(&buf)) return NULL; #if defined(_MSC_VER) || defined(sun) || defined(_AIX) @@ -745,7 +745,7 @@ mon_name[timeptr->tm_mon], timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, - 1900 + timeptr->tm_year); + timeptr->tm_year); } static PyObject * @@ -761,7 +761,7 @@ if (pylocaltime(&tt, &buf) == -1) return NULL; - } else if (!gettmarg(tup, &buf) || !checktm(&buf)) + } else if (!gettmarg(tup, &buf, 0) || !checktm(&buf)) return NULL; return _asctime(&buf); } @@ -782,6 +782,7 @@ return NULL; if (pylocaltime(&tt, &buf) == -1) return NULL; + buf.tm_year += 1900; return _asctime(&buf); } @@ -798,7 +799,7 @@ { struct tm buf; time_t tt; - if (!gettmarg(tup, &buf)) + if (!gettmarg(tup, &buf, 1900)) return NULL; #ifdef _AIX /* year < 1902 or year > 2037 */