Skip to content

Commit 41a99bc

Browse files
committed
Issue python#10934: Fixed and expanded Internaldate2tuple() and
Time2Internaldate() documentation. Thanks Joe Peterson for the report and the original patch.
1 parent e47e093 commit 41a99bc

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

Doc/library/imaplib.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ The following utility functions are defined:
8585

8686
.. function:: Internaldate2tuple(datestr)
8787

88-
Converts an IMAP4 INTERNALDATE string to Coordinated Universal Time. Returns a
89-
:mod:`time` module tuple.
90-
88+
Parse an IMAP4 ``INTERNALDATE`` string and return corresponding local
89+
time. The return value is a :class:`time.struct_time` tuple or
90+
None if the string has wrong format.
9191

9292
.. function:: Int2AP(num)
9393

@@ -102,9 +102,13 @@ The following utility functions are defined:
102102

103103
.. function:: Time2Internaldate(date_time)
104104

105-
Converts a :mod:`time` module tuple to an IMAP4 ``INTERNALDATE`` representation.
106-
Returns a string in the form: ``"DD-Mmm-YYYY HH:MM:SS +HHMM"`` (including
107-
double-quotes).
105+
Convert *date_time* to an IMAP4 ``INTERNALDATE`` representation. The
106+
return value is a string in the form: ``"DD-Mmm-YYYY HH:MM:SS
107+
+HHMM"`` (including double-quotes). The *date_time* argument can be a
108+
number (int or float) represening seconds since epoch (as returned
109+
by :func:`time.time`), a 9-tuple representing local time (as returned by
110+
:func:`time.localtime`), or a double-quoted string. In the last case, it
111+
is assumed to already be in the correct format.
108112

109113
Note that IMAP4 message numbers change as the mailbox changes; in particular,
110114
after an ``EXPUNGE`` command performs deletions the remaining messages are

Lib/imaplib.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,9 +1312,10 @@ def decode(self, inp):
13121312
'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
13131313

13141314
def Internaldate2tuple(resp):
1315-
"""Convert IMAP4 INTERNALDATE to UT.
1315+
"""Parse an IMAP4 INTERNALDATE string.
13161316
1317-
Returns Python time module tuple.
1317+
Return corresponding local time. The return value is a
1318+
time.struct_time tuple or None if the string has wrong format.
13181319
"""
13191320

13201321
mo = InternalDate.match(resp)
@@ -1381,9 +1382,14 @@ def ParseFlags(resp):
13811382

13821383
def Time2Internaldate(date_time):
13831384

1384-
"""Convert 'date_time' to IMAP4 INTERNALDATE representation.
1385+
"""Convert date_time to IMAP4 INTERNALDATE representation.
13851386
1386-
Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'
1387+
Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The
1388+
date_time argument can be a number (int or float) represening
1389+
seconds since epoch (as returned by time.time()), a 9-tuple
1390+
representing local time (as returned by time.localtime()), or a
1391+
double-quoted string. In the last case, it is assumed to already
1392+
be in the correct format.
13871393
"""
13881394

13891395
if isinstance(date_time, (int, float)):

0 commit comments

Comments
 (0)