Merged revisions 87919 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r87919 | alexander.belopolsky | 2011-01-10 20:21:25 -0500 (Mon, 10 Jan 2011) | 4 lines

  Issue #1726687: time.mktime() will now correctly compute value one
  second before epoch.  Original patch by Peter Wang, reported by Martin
  Blais.
........
This commit is contained in:
Alexander Belopolsky 2011-02-15 15:51:17 +00:00
parent 42bb7ca9e4
commit 6233b36d14
2 changed files with 14 additions and 1 deletions

View File

@ -223,6 +223,16 @@ class TimeTestCase(unittest.TestCase):
t1 = time.mktime(lt1) t1 = time.mktime(lt1)
self.assertTrue(0 <= (t1-t0) < 0.2) self.assertTrue(0 <= (t1-t0) < 0.2)
def test_mktime(self):
# Issue #1726687
for t in (-2, -1, 0, 1):
try:
tt = time.localtime(t)
except (OverflowError, ValueError):
pass
self.assertEqual(time.mktime(tt), t)
def test_main(): def test_main():
test_support.run_unittest(TimeTestCase) test_support.run_unittest(TimeTestCase)

View File

@ -632,8 +632,11 @@ time_mktime(PyObject *self, PyObject *tup)
time_t tt; time_t tt;
if (!gettmarg(tup, &buf)) if (!gettmarg(tup, &buf))
return NULL; return NULL;
buf.tm_wday = -1; /* sentinel; original value ignored */
tt = mktime(&buf); tt = mktime(&buf);
if (tt == (time_t)(-1)) { /* Return value of -1 does not necessarily mean an error, but tm_wday
* cannot remain set to -1 if mktime succedded. */
if (tt == (time_t)(-1) && buf.tm_wday == -1) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"mktime argument out of range"); "mktime argument out of range");
return NULL; return NULL;