Index: Lib/imaplib.py =================================================================== --- Lib/imaplib.py (revision 88239) +++ Lib/imaplib.py (working copy) @@ -22,7 +22,7 @@ __version__ = "2.58" -import binascii, errno, random, re, socket, subprocess, sys, time +import binascii, errno, random, re, socket, subprocess, sys, time, calendar try: import ssl @@ -1340,22 +1340,12 @@ zone = -zone tt = (year, mon, day, hour, min, sec, -1, -1, -1) + utc = calendar.timegm(tt) - zone - utc = time.mktime(tt) + return time.localtime(utc) - # Following is necessary because the time module has no 'mkgmtime'. - # 'mktime' assumes arg in local timezone, so adds timezone/altzone. - lt = time.localtime(utc) - if time.daylight and lt[-1]: - zone = zone + time.altzone - else: - zone = zone + time.timezone - return time.localtime(utc - zone) - - - def Int2AP(num): """Convert integer to A-P string representation.""" Index: Lib/test/test_imaplib.py =================================================================== --- Lib/test/test_imaplib.py (revision 88239) +++ Lib/test/test_imaplib.py (working copy) @@ -36,6 +36,23 @@ b'25 (INTERNALDATE "31-Dec-1999 12:30:00 -1130")') self.assertEqual(time.mktime(tt), t0) + # Test for DST-related bug (issue 10941) + if 'TZ' in os.environ: + saved_tz = os.environ['TZ'] + else: + saved_tz = None + os.environ['TZ'] = 'MST+07MDT,M4.1.0,M10.5.0' + time.tzset() + self.assertNotEqual(imaplib.Internaldate2tuple( + b'25 (INTERNALDATE "02-Apr-2000 02:30:00 +0000")'), + imaplib.Internaldate2tuple( + b'25 (INTERNALDATE "02-Apr-2000 03:30:00 +0000")')) + if saved_tz == None: + del os.environ['TZ'] + else: + os.environ['TZ'] = saved_tz + time.tzset() + def test_that_Time2Internaldate_returns_a_result(self): # We can check only that it successfully produces a result, # not the correctness of the result itself, since the result