diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -64,7 +64,7 @@ self.assertEqual(dar(7, -3), -2) self.assertEqual(dar(-7, -3), 2) - # ties to even - eight cases: + # ties to even - eight cases: # (2 signs of a) x (2 signs of b) x (even / odd quotient) self.assertEqual(dar(10, 4), 2) self.assertEqual(dar(-10, 4), -2) @@ -76,7 +76,7 @@ self.assertEqual(dar(6, -4), -2) self.assertEqual(dar(-6, -4), 2) - + ############################################################################# # tzinfo tests diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -489,6 +489,7 @@ class _TestAsctimeYear: _format = '%d' + MINYEAR = TIME_MINYEAR def yearstr(self, y): return time.asctime((y,) + (0,) * 8).split()[-1] @@ -509,6 +510,7 @@ _format = '%04d' else: _format = '%d' + MINYEAR = TIME_MINYEAR + 1900 def yearstr(self, y): return time.strftime('%Y', (y,) + (0,) * 8) @@ -570,10 +572,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 --git a/Modules/timemodule.c b/Modules/timemodule.c --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -424,7 +424,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; @@ -441,7 +441,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--; @@ -595,7 +595,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) @@ -768,7 +768,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 * @@ -784,7 +784,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); } @@ -805,6 +805,7 @@ return NULL; if (pylocaltime(&tt, &buf) == -1) return NULL; + buf.tm_year += 1900; return _asctime(&buf); } @@ -821,7 +822,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 */