Fix dc:date export for midnight time

Change-Id: I2fc40055e8949348925159a7e10f231a2573950c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166757
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski
2024-04-26 19:17:09 +05:00
parent f5c3ec505b
commit 60f65e63b4
3 changed files with 36 additions and 2 deletions

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
<office:body>
<office:text>
<text:tracked-changes text:track-changes="false">
<text:changed-region xml:id="ct1" text:id="ct1">
<text:deletion>
<office:change-info>
<dc:creator>John Doe</dc:creator>
<dc:date>2001-01-01T00:00:00</dc:date>
</office:change-info>
</text:deletion>
</text:changed-region>
</text:tracked-changes>
<text:p><text:change-start text:change-id="ct1"/>Deleted text<text:change-end text:change-id="ct1"/></text:p>
</office:text>
</office:body>
</office:document>

View File

@@ -1609,6 +1609,21 @@ CPPUNIT_TEST_FIXTURE(Test, testDeletedTableAutostylesExport)
loadAndReload("deleted_table.fodt");
}
CPPUNIT_TEST_FIXTURE(Test, testMidnightRedlineDatetime)
{
// Given a document with a tracked change with a midnight datetime:
// make sure that it succeeds export and import validation. Before the fix, this failed:
// - Error: "2001-01-01" does not satisfy the "dateTime" type
// because "2001-01-01T00:00:00" became "2001-01-01" on roundtrip.
loadAndReload("midnight_redline.fodt");
xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
assertXPathContent(pXmlDoc,
"//office:body/office:text/text:tracked-changes/text:changed-region/"
"text:deletion/office:change-info/dc:date"_ostr,
u"2001-01-01T00:00:00"_ustr);
}
} // end of anonymous namespace
CPPUNIT_PLUGIN_IMPLEMENT();

View File

@@ -469,7 +469,7 @@ void XMLRedlineExport::ExportChangeInfo(
OUStringBuffer sBuf;
::sax::Converter::convertDateTime(sBuf, bRemovePersonalInfo
? util::DateTime(0, 0, 0, 0, 1, 1, 1970, true) // Epoch time
: aDateTime, nullptr);
: aDateTime, nullptr, true);
SvXMLElementExport aDateElem( rExport, XML_NAMESPACE_DC,
XML_DATE, true,
false );
@@ -521,7 +521,7 @@ void XMLRedlineExport::ExportChangeInfo(
OUStringBuffer sBuf;
::sax::Converter::convertDateTime(sBuf, bRemovePersonalInfo
? util::DateTime(0, 0, 0, 0, 1, 1, 1970, true) // Epoch time
: aDateTime, nullptr);
: aDateTime, nullptr, true);
SvXMLElementExport aDateElem( rExport, XML_NAMESPACE_DC,
XML_DATE, true,
false );