diff options
author | Ronald Oussoren <ronaldoussoren@mac.com> | 2024-01-01 20:31:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-01 20:31:43 (GMT) |
commit | 8e4ff5c7885abb04a66d079499335c4d46106aff (patch) | |
tree | d3e5f9532d275776595708b9f3377dc64ff78d86 | |
parent | b4b2cc101216ae1017898dfbe43c90da2fd0a308 (diff) | |
download | cpython-8e4ff5c7885abb04a66d079499335c4d46106aff.zip cpython-8e4ff5c7885abb04a66d079499335c4d46106aff.tar.gz cpython-8e4ff5c7885abb04a66d079499335c4d46106aff.tar.bz2 |
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
-rw-r--r-- | Lib/plistlib.py | 4 | ||||
-rw-r--r-- | Lib/test/test_plistlib.py | 5 |
2 files changed, 4 insertions, 5 deletions
diff --git a/Lib/plistlib.py b/Lib/plistlib.py index 0fc1b5c..6eb70ce 100644 --- a/Lib/plistlib.py +++ b/Lib/plistlib.py @@ -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() diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index d41975f..010393a 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -881,12 +881,11 @@ class TestPlistlib(unittest.TestCase): # Save a naive datetime with aware_datetime set to true. This will lead # to having different time as compared to the current machine's # timezone, which is UTC. - dt = datetime.datetime(2345, 6, 7, 8, tzinfo=None) + dt = datetime.datetime(2003, 6, 7, 8, tzinfo=None) for fmt in ALL_FORMATS: s = plistlib.dumps(dt, fmt=fmt, aware_datetime=True) parsed = plistlib.loads(s, aware_datetime=False) - expected = dt + datetime.timedelta(seconds=time.timezone) - self.assertEqual(parsed, expected) + self.assertEqual(parsed, dt) class TestBinaryPlistlib(unittest.TestCase): |