tdf#133377 OOXML Fix storage of date in Custom Properties

During exporting documents into OOXML formats (docx, xlsx, pptx),
if custom properties have Date format, the day and year were switched.

This commit fixes that.

Change-Id: Id497602eb3354de78bfd52bf5ef61d32aafd957d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104450
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104463
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index e0e1933..3521a52 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -826,11 +826,13 @@ writeCustomProperties( XmlFilterBase& rSelf, const Reference< XDocumentPropertie
                    util::DateTime aDateTime;
                    if ( rProp.Value >>= num )
                    {
                        // i4 - 4-byte signed integer
                        // r8 - 8-byte real number
                        writeElement( pAppProps, FSNS( XML_vt, XML_i4 ), num );
                    }
                    else if ( rProp.Value >>= aDate )
                    {
                        aDateTime = util::DateTime( 0, 0 , 0, 0, aDate.Year, aDate.Month, aDate.Day, true );
                        aDateTime = util::DateTime( 0, 0 , 0, 0, aDate.Day, aDate.Month, aDate.Year, true );
                        writeElement( pAppProps, FSNS( XML_vt, XML_filetime ), aDateTime);
                    }
                    else if ( rProp.Value >>= aDuration )
diff --git a/sw/qa/extras/ooxmlexport/data/custom-properties.docx b/sw/qa/extras/ooxmlexport/data/custom-properties.docx
new file mode 100644
index 0000000..33cce91
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/custom-properties.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
index fa75e2d..9640fb7 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
@@ -78,6 +78,53 @@ DECLARE_OOXMLEXPORT_TEST(testPageGraphicBackground, "page-graphic-background.odt
    CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xPageStyle, "BackColor"));
}


DECLARE_OOXMLEXPORT_TEST(testCustomProperties, "custom-properties.docx")
{
    // tdf#133377 FILESAVE XLSX: Make sure the custom/core/application file properties
    // are stored correctly after roundtrip to .docx

    // Extended file properties - specific to Office package,
    // eg. docx - Number of Pages, pptx - Number of Slides
    xmlDocUniquePtr pXmlDoc = parseExport("docProps/app.xml");
    if (!pXmlDoc)
        return;

    assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Paragraphs", "1");
    //assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Lines", "1");
    assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Pages", "1");
    assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Words", "3");
    assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Characters", "21");
    assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:CharactersWithSpaces", "23");
    assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Company", "hhhhkompany");

    // Custom file properties - defined by user
    xmlDocUniquePtr pCustomXml = parseExport("docProps/custom.xml");
    assertXPath(pCustomXml, "/custom-properties:Properties/custom-properties:property[12]",
                "name", "testDateProperty");
    assertXPathContent(pCustomXml, "/custom-properties:Properties/custom-properties:property[12]/vt:filetime",
                       "1982-04-19T10:00:00Z");
    assertXPath(pCustomXml, "/custom-properties:Properties/custom-properties:property[14]",
                "name", "testNegativeNumberProperty");
    assertXPathContent(pCustomXml, "/custom-properties:Properties/custom-properties:property[14]/vt:i4",
                       "-100");
    assertXPath(pCustomXml, "/custom-properties:Properties/custom-properties:property[17]",
                "name", "testTextProperty");
    assertXPathContent(pCustomXml, "/custom-properties:Properties/custom-properties:property[17]/vt:lpwstr",
                       "testPropertyValue");
    assertXPath(pCustomXml, "/custom-properties:Properties/custom-properties:property[18]",
                "name", "testYesNoProperty");
    assertXPathContent(pCustomXml, "/custom-properties:Properties/custom-properties:property[18]/vt:bool",
                       "1");

    // Core file properties - common for all packages (eg. creation date, modify date)
    pXmlDoc = parseExport("docProps/core.xml");
    assertXPathContent(pXmlDoc, "/cp:coreProperties/dc:creator", "Bartosz Kosiorek");
    assertXPathContent(pXmlDoc, "/cp:coreProperties/dc:description", "cccckomentarzglowny");
    assertXPathContent(pXmlDoc, "/cp:coreProperties/cp:lastPrinted", "2020-10-15T07:42:00Z");
    assertXPathContent(pXmlDoc, "/cp:coreProperties/dcterms:created", "2020-10-14T16:23:00Z");
}

DECLARE_OOXMLEXPORT_TEST(testZoom, "zoom.docx")
{
    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx
index 8769e38..090044e 100644
--- a/sw/qa/inc/swmodeltestbase.hxx
+++ b/sw/qa/inc/swmodeltestbase.hxx
@@ -985,7 +985,11 @@ protected:
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("m"), BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/math"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ContentType"), BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("lc"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("cp"), BAD_CAST("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("extended-properties"), BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("custom-properties"), BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("vt"), BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dcterms"), BAD_CAST("http://purl.org/dc/terms/"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a14"), BAD_CAST("http://schemas.microsoft.com/office/drawing/2010/main"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("c"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/chart"));
        xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("o"), BAD_CAST("urn:schemas-microsoft-com:office:office"));