diff --git a/Lib/imaplib.py b/Lib/imaplib.py index cbcf107dc60..ed785ed3d42 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1069,12 +1069,12 @@ def Time2Internaldate(date_time): Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"' """ - dttype = type(date_time) - if dttype is type(1) or dttype is type(1.1): + if isinstance(date_time, int) or isinstance(date_time, float): tt = time.localtime(date_time) - elif dttype is type(()): + elif isinstance(date_time, tuple) or \ + isinstance(date_time, time.struct_time): tt = date_time - elif dttype is type(""): + elif isinstance(date_time, str): return date_time # Assume in correct format else: raise ValueError @@ -1085,7 +1085,7 @@ def Time2Internaldate(date_time): zone = -time.altzone else: zone = -time.timezone - return '"' + dt + " %+02d%02d" % divmod(zone/60, 60) + '"' + return '"' + dt + " %+03d%02d" % divmod(zone/60, 60) + '"' diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py new file mode 100644 index 00000000000..c0d60772ffc --- /dev/null +++ b/Lib/test/test_imaplib.py @@ -0,0 +1,14 @@ +from test_support import verify,verbose +import imaplib +import time + +# We can check only that it successfully produces a result, +# not the correctness of the result itself, since the result +# depends on the timezone the machine is in. + +timevalues = [2000000000, 2000000000.0, time.localtime(2000000000), + "18-May-2033 05:33:20 +0200"] + +for t in timevalues: + imaplib.Time2Internaldate(t) +