invalid timestamps in core document properties
Openpyxl currently writes timestamp strings like 2023-12-11T19:03:54+00:00Z
into the document properties in docProps/core.xml. The presence of both numerical time zone '+00:00' and UTC indicator 'Z' makes this invalid. This behavior was introduced in !435 (merged).
datetime.datetime.utcnow()
and datetime.datetime.now(tz=datetime.timezone.utc)
are not the same; the former returns a naive datetime while the latter returns a timezone-aware one. This resulted in a test failure that was also "fixed" in !435 (merged). However, it was not noticed that the code writing the document properties in openpyxl/packaging/core.py#L33 is assuming a naive datetime.
To fix this you could either use datetime.datetime.now(tz=datetime.timezone.utc).replace(tzinfo=None)
, or drop the + 'Z'
from openpyxl/packaging/core.py#L33, or teach the NestedDateTime
class to cope with both naive and aware datetimes. (Excel writes the timestamps with UTC timezone and using the 'Z' timezone indicator.)