diff -r 760f222103c7 Lib/datetime.py --- a/Lib/datetime.py Mon Mar 02 09:36:48 2015 -0500 +++ b/Lib/datetime.py Tue Mar 03 15:43:23 2015 +0100 @@ -284,7 +284,7 @@ def _check_time_fields(hour, minute, sec if not 0 <= minute <= 59: raise ValueError('minute must be in 0..59', minute) if not 0 <= second <= 59: - raise ValueError('second must be in 0..59', second) + raise ValueError('second must be in 0..60', second) if not 0 <= microsecond <= 999999: raise ValueError('microsecond must be in 0..999999', microsecond) return hour, minute, second, microsecond @@ -1322,6 +1322,9 @@ class datetime(date): self.__setstate(year, month) self._hashcode = -1 return self + if second == 60: + # Issue #23574: leap seconds are ignored + second = 59 year, month, day = _check_date_fields(year, month, day) hour, minute, second, microsecond = _check_time_fields( hour, minute, second, microsecond) @@ -1385,7 +1388,6 @@ class datetime(date): t += 1 us = 0 y, m, d, hh, mm, ss, weekday, jday, dst = converter(t) - ss = min(ss, 59) # clamp out leap seconds if the platform has them result = cls(y, m, d, hh, mm, ss, us, tz) if tz is not None: result = tz.fromutc(result) diff -r 760f222103c7 Lib/test/datetimetester.py --- a/Lib/test/datetimetester.py Mon Mar 02 09:36:48 2015 -0500 +++ b/Lib/test/datetimetester.py Tue Mar 03 15:43:23 2015 +0100 @@ -1625,7 +1625,7 @@ class TestDateTime(TestDate): self.theclass(2000, 1, 31, 23, 59, 0) # no exception self.theclass(2000, 1, 31, 23, 59, 59) # no exception self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 59, -1) - self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 59, 60) + self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 59, 61) # bad microseconds self.theclass(2000, 1, 31, 23, 59, 59, 0) # no exception self.theclass(2000, 1, 31, 23, 59, 59, 999999) # no exception @@ -2094,6 +2094,14 @@ class TestDateTime(TestDate): self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month + dt1.second - 7) + def test_leap_second(self): + # Issue #23574: leap seconds are ignored + dt = self.theclass(2012, 6, 30, 23, 59, 60) + self.assertEqual(dt.second, 59) + + self.assertRaises(ValueError, self.theclass, 2012, 6, 30, 23, 59, 61) + + class TestSubclassDateTime(TestDateTime): theclass = SubclassDatetime # Override tests not designed for subclass diff -r 760f222103c7 Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c Mon Mar 02 09:36:48 2015 -0500 +++ b/Modules/_datetimemodule.c Tue Mar 03 15:43:23 2015 +0100 @@ -425,7 +425,7 @@ check_time_args(int h, int m, int s, int } if (s < 0 || s > 59) { PyErr_SetString(PyExc_ValueError, - "second must be in 0..59"); + "second must be in 0..60"); return -1; } if (us < 0 || us > 999999) { @@ -4023,6 +4023,9 @@ datetime_new(PyTypeObject *type, PyObjec if (PyArg_ParseTupleAndKeywords(args, kw, "iii|iiiiO", datetime_kws, &year, &month, &day, &hour, &minute, &second, &usecond, &tzinfo)) { + /* Issue #23574: leap seconds are ignored */ + if (second == 60) + second = 59; if (check_date_args(year, month, day) < 0) return NULL; if (check_time_args(hour, minute, second, usecond) < 0) @@ -4058,14 +4061,6 @@ datetime_from_timet_and_us(PyObject *cls return PyErr_SetFromErrno(PyExc_OSError); } - /* The platform localtime/gmtime may insert leap seconds, - * indicated by tm->tm_sec > 59. We don't care about them, - * except to the extent that passing them on to the datetime - * constructor would raise ValueError for a reason that - * made no sense to the user. - */ - if (tm->tm_sec > 59) - tm->tm_sec = 59; return PyObject_CallFunction(cls, "iiiiiiiO", tm->tm_year + 1900, tm->tm_mon + 1,