diff --git a/openpyxl/cell/_writer.py b/openpyxl/cell/_writer.py index 32f753f98d916dc6d56d94e58d7587dbf441e9bc..fe496d840335c5fdcd6d4e49c60ac0ed53aa899b 100644 --- a/openpyxl/cell/_writer.py +++ b/openpyxl/cell/_writer.py @@ -3,7 +3,7 @@ from openpyxl.compat import safe_string from openpyxl.xml.functions import Element, SubElement, whitespace, XML_NS, REL_NS from openpyxl import LXML -from openpyxl.utils.datetime import to_excel, days_to_time +from openpyxl.utils.datetime import to_excel, days_to_time, to_ISO8601 from datetime import timedelta @@ -25,7 +25,7 @@ def _set_attributes(cell, styled=None): if cell.data_type == "d": if cell.parent.parent.iso_dates and not isinstance(value, timedelta): - value = value.isoformat() + value = to_ISO8601(value) else: attrs['t'] = "n" value = to_excel(value, cell.parent.parent.epoch) diff --git a/openpyxl/packaging/core.py b/openpyxl/packaging/core.py index d8320b6f26f85ceee9c10d8e2908bd8efd5a7675..24593f4b1b5f875fc48552a421f1129004f6f068 100644 --- a/openpyxl/packaging/core.py +++ b/openpyxl/packaging/core.py @@ -3,11 +3,6 @@ import datetime from openpyxl.compat import safe_string -from openpyxl.utils.datetime import ( - CALENDAR_WINDOWS_1900, - to_ISO8601, - from_ISO8601, -) from openpyxl.descriptors import ( String, DateTime, @@ -34,7 +29,7 @@ class NestedDateTime(DateTime, NestedText): tagname = "{%s}%s" % (namespace, tagname) el = Element(tagname) if value is not None: - el.text = to_ISO8601(value) + el.text = value.isoformat(timespec="seconds") + 'Z' return el diff --git a/openpyxl/packaging/tests/test_core.py b/openpyxl/packaging/tests/test_core.py index c57973eded4a4d7ccf83407e4af601b08e40eca0..85fcb982eda3ca33897659ed75b6beed14e1dda4 100644 --- a/openpyxl/packaging/tests/test_core.py +++ b/openpyxl/packaging/tests/test_core.py @@ -78,7 +78,7 @@ def test_from_tree(datadir, SampleProperties): def test_qualified_datetime(): from ..core import QualifiedDateTime dt = QualifiedDateTime() - tree = dt.to_tree("time", datetime.datetime(2015, 7, 20, 12, 30)) + tree = dt.to_tree("time", datetime.datetime(2015, 7, 20, 12, 30, 00, 123456)) xml = tostring(tree) expected = """