Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Lib/imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,9 +1869,8 @@ def Time2Internaldate(date_time):
dt = datetime.fromtimestamp(date_time,
timezone.utc).astimezone()
elif isinstance(date_time, tuple):
try:
gmtoff = date_time.tm_gmtoff
except AttributeError:
gmtoff = getattr(date_time, "tm_gmtoff", None)
if gmtoff is None:
if time.daylight:
dst = date_time[8]
if dst == -1:
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def test_Time2Internaldate(self):
internal = imaplib.Time2Internaldate(t)
self.assertEqual(internal, expected)

@run_with_tz('STD-1DST,M3.2.0,M11.1.0')
def test_Time2Internaldate_datetime_timetuple(self):
date_time = datetime.fromtimestamp(2000000000).timetuple()
self.assertIsNone(date_time.tm_gmtoff)
self.assertEqual(
imaplib.Time2Internaldate(date_time),
'"18-May-2033 05:33:20 +0200"',
)

def test_that_Time2Internaldate_returns_a_result(self):
# Without tzset, we can check only that it successfully
# produces a result, not the correctness of the result itself,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :func:`imaplib.Time2Internaldate` to use the local timezone offset for
``time.struct_time`` values with ``tm_gmtoff`` set to ``None``, as returned by
``datetime.datetime.timetuple()``. Contributed by Xiao Yuan.
Loading