]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 87919 via svnmerge from
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Tue, 15 Feb 2011 15:51:17 +0000 (15:51 +0000)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Tue, 15 Feb 2011 15:51:17 +0000 (15:51 +0000)
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.
........

Lib/test/test_time.py
Modules/timemodule.c

index 0cec3e44914d2916dcc85ac3de30bda4d9703104..d70b59f1d0ee791f1d6bc40eab5c9d23366a78be 100644 (file)
@@ -223,6 +223,16 @@ class TimeTestCase(unittest.TestCase):
         t1 = time.mktime(lt1)
         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():
     test_support.run_unittest(TimeTestCase)
 
index 1ebee6f00823b53cf022066c5ea012a9ec3a1ca6..61c1cccba66cddfb51542bcb95a85ab414cff2b3 100644 (file)
@@ -632,8 +632,11 @@ time_mktime(PyObject *self, PyObject *tup)
     time_t tt;
     if (!gettmarg(tup, &buf))
         return NULL;
+    buf.tm_wday = -1;  /* sentinel; original value ignored */
     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,
                         "mktime argument out of range");
         return NULL;