From: Alexander Belopolsky Date: Fri, 22 Jun 2012 00:34:09 +0000 (-0400) Subject: Issue #14653: email.utils.mktime_tz() no longer relies on system X-Git-Tag: v3.3.0b1~164^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a07548e97bd819884ed1ddcfedb0fcbcbfdc58fe;p=python Issue #14653: email.utils.mktime_tz() no longer relies on system mktime() when timezone offest is supplied. --- diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py index a295757281..79573c6177 100644 --- a/Lib/email/_parseaddr.py +++ b/Lib/email/_parseaddr.py @@ -13,7 +13,7 @@ __all__ = [ 'quote', ] -import time +import time, calendar SPACE = ' ' EMPTYSTRING = '' @@ -152,13 +152,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 5db34dc9d7..65b3ebd211 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -2585,6 +2585,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 e59ed37d61..789f7f78bb 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -73,6 +73,9 @@ Core and Builtins Library ------- +- Issue #14653: email.utils.mktime_tz() no longer relies on system + mktime() when timezone offest is supplied. + - Fix GzipFile's handling of filenames given as bytes objects. - Issue #15101: Make pool finalizer avoid joining current thread.