]> granicus.if.org Git - python/commitdiff
Issue #14653: email.utils.mktime_tz() no longer relies on system
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Fri, 22 Jun 2012 00:34:09 +0000 (20:34 -0400)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Fri, 22 Jun 2012 00:34:09 +0000 (20:34 -0400)
mktime() when timezone offest is supplied.

Lib/email/_parseaddr.py
Lib/email/test/test_email.py
Misc/NEWS

index a295757281763489eed296ecf4adf65aee83204d..79573c6177847546cbaea38eefe03f75023b7ecc 100644 (file)
@@ -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):
index 5db34dc9d77bdaf72248c9e63d4bb19c0469af21..65b3ebd21186acdce98f1de7513fe2eca1c55bb9 100644 (file)
@@ -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.
 
index e59ed37d6119b05a15b137239a49a13aaeb00226..789f7f78bb4681b20f4416466814916dd7438f2b 100644 (file)
--- 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.