From e99d3a160ca622fff737a0f835f78e2c4705f9cc Mon Sep 17 00:00:00 2001 From: Alexander Belopolsky Date: Thu, 21 Jun 2012 20:57:39 -0400 Subject: [PATCH] Issue #14653: email.utils.mktime_tz() no longer relies on system mktime() when timezone offest is supplied. --- Lib/email/_parseaddr.py | 8 ++++---- Lib/email/test/test_email.py | 6 ++++++ Misc/NEWS | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py index 3bd4ba44030..690db2c22d3 100644 --- a/Lib/email/_parseaddr.py +++ b/Lib/email/_parseaddr.py @@ -13,7 +13,7 @@ __all__ = [ 'quote', ] -import time +import time, calendar SPACE = ' ' EMPTYSTRING = '' @@ -150,13 +150,13 @@ def parsedate(data): def mktime_tz(data): - """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" + """Turn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.""" if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: - t = time.mktime(data[:8] + (0,)) - return t - data[9] - time.timezone + t = calendar.timegm(data) + return t - data[9] def quote(str): diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index 5c9a7253055..d86bfd17431 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -2262,6 +2262,12 @@ class TestMiscellaneous(TestEmailBase): eq(time.localtime(t)[:6], timetup[:6]) eq(int(time.strftime('%Y', timetup[:9])), 2003) + def test_mktime_tz(self): + self.assertEqual(utils.mktime_tz((1970, 1, 1, 0, 0, 0, + -1, -1, -1, 0)), 0) + self.assertEqual(utils.mktime_tz((1970, 1, 1, 0, 0, 0, + -1, -1, -1, 1234)), -1234) + def test_parsedate_y2k(self): """Test for parsing a date with a two-digit year. diff --git a/Misc/NEWS b/Misc/NEWS index 4ce3e21e85f..db28db11a03 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -70,6 +70,9 @@ Core and Builtins Library ------- +- Issue #14653: email.utils.mktime_tz() no longer relies on system + mktime() when timezone offest is supplied. + - Issue #15101: Make pool finalizer avoid joining current thread. - Issue #15054: A bug in tokenize.tokenize that caused string literals