]> 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:57:39 +0000 (20:57 -0400)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Fri, 22 Jun 2012 00:57:39 +0000 (20:57 -0400)
mktime() when timezone offest is supplied.

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

index 3bd4ba44030e426a32be73c49d4aed1b21f7c7ed..690db2c22d34d358b6707d6befa0fcf96e6373bc 100644 (file)
@@ -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):
index 5c9a7253055a3b6c5f26281c10534e5aa6ae4388..d86bfd174313bd57697c89f1ca1a0e908848b95a 100644 (file)
@@ -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.
 
index 4ce3e21e85fdaf0732504975d32338c35187aace..db28db11a037cca03a8bc5e9b79fe47d0799eb27 100644 (file)
--- 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