Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Saving non-aware datetimes will use the old behaviour regardless of t…
…he aware_datimetime setting
  • Loading branch information
ronaldoussoren committed Jan 1, 2024
commit f9b6c0a3bedd9d440bb1212d3127e5817ec6e98a
4 changes: 2 additions & 2 deletions Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _date_from_string(s, aware_datetime):


def _date_to_string(d, aware_datetime):
if aware_datetime:
if aware_datetime and d.tzinfo is not None:
d = d.astimezone(datetime.UTC)
return '%04d-%02d-%02dT%02d:%02d:%02dZ' % (
d.year, d.month, d.day,
Expand Down Expand Up @@ -791,7 +791,7 @@ def _write_object(self, value):
self._fp.write(struct.pack('>Bd', 0x23, value))

elif isinstance(value, datetime.datetime):
if self._aware_datetime:
if self._aware_datetime and value.tzinfo is not None:
dt = value.astimezone(datetime.UTC)
offset = dt - datetime.datetime(2001, 1, 1, tzinfo=datetime.UTC)
f = offset.total_seconds()
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,7 @@ def test_dump_naive_datetime_with_aware_datetime_option(self):
for fmt in ALL_FORMATS:
s = plistlib.dumps(dt, fmt=fmt, aware_datetime=True)
parsed = plistlib.loads(s, aware_datetime=False)
expected = dt + 2 * datetime.timedelta(seconds=time.timezone)
self.assertEqual(parsed, expected)
self.assertEqual(parsed, dt)


class TestBinaryPlistlib(unittest.TestCase):
Expand Down