Issue #14653: email.utils.mktime_tz() no longer relies on system

mktime() when timezone offest is supplied.
This commit is contained in:
Alexander Belopolsky 2012-06-21 20:48:23 -04:00
commit 76935b9c8c
3 changed files with 13 additions and 4 deletions

View File

@ -13,7 +13,7 @@ __all__ = [
'quote', 'quote',
] ]
import time import time, calendar
SPACE = ' ' SPACE = ' '
EMPTYSTRING = '' EMPTYSTRING = ''
@ -177,13 +177,13 @@ def parsedate(data):
def mktime_tz(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: if data[9] is None:
# No zone info, so localtime is better assumption than GMT # No zone info, so localtime is better assumption than GMT
return time.mktime(data[:8] + (-1,)) return time.mktime(data[:8] + (-1,))
else: else:
t = time.mktime(data[:8] + (0,)) t = calendar.timegm(data)
return t - data[9] - time.timezone return t - data[9]
def quote(str): def quote(str):

View File

@ -2722,6 +2722,12 @@ class TestMiscellaneous(TestEmailBase):
eq(time.localtime(t)[:6], timetup[:6]) eq(time.localtime(t)[:6], timetup[:6])
eq(int(time.strftime('%Y', timetup[:9])), 2003) 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): def test_parsedate_y2k(self):
"""Test for parsing a date with a two-digit year. """Test for parsing a date with a two-digit year.

View File

@ -37,6 +37,9 @@ Core and Builtins
Library Library
------- -------
- Issue #14653: email.utils.mktime_tz() no longer relies on system
mktime() when timezone offest is supplied.
- Issue #14684: zlib.compressobj() and zlib.decompressobj() now support the use - Issue #14684: zlib.compressobj() and zlib.decompressobj() now support the use
of predefined compression dictionaries. Original patch by Sam Rushing. of predefined compression dictionaries. Original patch by Sam Rushing.