Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fb96f4

Browse files
committed
Merged revisions 87919 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 725cb96 commit 4fb96f4

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/test/test_time.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ def test_localtime_without_arg(self):
233233
t1 = time.mktime(lt1)
234234
self.assertTrue(0 <= (t1-t0) < 0.2)
235235

236+
def test_mktime(self):
237+
# Issue #1726687
238+
for t in (-2, -1, 0, 1):
239+
try:
240+
tt = time.localtime(t)
241+
except (OverflowError, ValueError):
242+
pass
243+
self.assertEqual(time.mktime(tt), t)
244+
236245
class TestLocale(unittest.TestCase):
237246
def setUp(self):
238247
self.oldloc = locale.setlocale(locale.LC_ALL)

Modules/timemodule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,11 @@ time_mktime(PyObject *self, PyObject *tup)
703703
time_t tt;
704704
if (!gettmarg(tup, &buf))
705705
return NULL;
706+
buf.tm_wday = -1; /* sentinel; original value ignored */
706707
tt = mktime(&buf);
707-
if (tt == (time_t)(-1)) {
708+
/* Return value of -1 does not necessarily mean an error, but tm_wday
709+
* cannot remain set to -1 if mktime succedded. */
710+
if (tt == (time_t)(-1) && buf.tm_wday == -1) {
708711
PyErr_SetString(PyExc_OverflowError,
709712
"mktime argument out of range");
710713
return NULL;

0 commit comments

Comments
 (0)