[Python-checkins] r88425 - in python/branches/release31-maint: Lib/test/test_time.py Modules/timemodule.c

alexander.belopolsky python-checkins at python.org
Tue Feb 15 16:41:00 CET 2011


Author: alexander.belopolsky
Date: Tue Feb 15 16:40:59 2011
New Revision: 88425

Log:
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.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/test/test_time.py
   python/branches/release31-maint/Modules/timemodule.c

Modified: python/branches/release31-maint/Lib/test/test_time.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_time.py	(original)
+++ python/branches/release31-maint/Lib/test/test_time.py	Tue Feb 15 16:40:59 2011
@@ -233,6 +233,15 @@
         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)
+
 class TestLocale(unittest.TestCase):
     def setUp(self):
         self.oldloc = locale.setlocale(locale.LC_ALL)

Modified: python/branches/release31-maint/Modules/timemodule.c
==============================================================================
--- python/branches/release31-maint/Modules/timemodule.c	(original)
+++ python/branches/release31-maint/Modules/timemodule.c	Tue Feb 15 16:40:59 2011
@@ -703,8 +703,11 @@
     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;


More information about the Python-checkins mailing list