gh-53502: Fixes for tests in gh-113363 (#113627)

* gh-53502: Fixes for tests in gh-113363

* Use 32-bit compatible date in test_dump_naive_datetime_with_aware_datetime_option

* Saving non-aware datetimes will use the old behaviour regardless of the aware_datimetime setting
This commit is contained in:
Ronald Oussoren 2024-01-01 21:31:43 +01:00 committed by GitHub
parent b4b2cc1012
commit 8e4ff5c788
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View file

@ -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,
@ -791,7 +791,7 @@ class _BinaryPlistWriter (object):
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()