Index: Doc/library/imaplib.rst =================================================================== --- Doc/library/imaplib.rst (revision 88061) +++ Doc/library/imaplib.rst (working copy) @@ -84,8 +84,8 @@ .. function:: Internaldate2tuple(datestr) - Converts an IMAP4 INTERNALDATE string to Coordinated Universal Time. Returns a - :mod:`time` module tuple. + Converts an IMAP4 INTERNALDATE string to local time. + Returns a :mod:`time` module tuple. .. function:: Int2AP(num) @@ -101,7 +101,8 @@ .. function:: Time2Internaldate(date_time) - Converts a :mod:`time` module tuple to an IMAP4 ``INTERNALDATE`` representation. + Converts a :mod:`time` module tuple (local time) to an + IMAP4 ``INTERNALDATE`` representation. Returns a string in the form: ``"DD-Mmm-YYYY HH:MM:SS +HHMM"`` (including double-quotes). Index: Lib/imaplib.py =================================================================== --- Lib/imaplib.py (revision 88061) +++ 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 __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate"] @@ -1321,7 +1321,7 @@ 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12} def Internaldate2tuple(resp): - """Convert IMAP4 INTERNALDATE to UT. + """Convert IMAP4 INTERNALDATE to local time. Returns Python time module tuple. """ @@ -1348,22 +1348,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.""" @@ -1390,7 +1380,7 @@ def Time2Internaldate(date_time): - """Convert 'date_time' to IMAP4 INTERNALDATE representation. + """Convert 'date_time' (local time) to IMAP4 INTERNALDATE representation. Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"' """