sc/source/filter/oox/workbooksettings.cxx |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

New commits:
commit 5956e3e8c17ec8917b8c456f4e76088a5798c226
Author:     Justin Luth <[email protected]>
AuthorDate: Wed Dec 3 16:14:52 2025 -0500
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Dec 8 14:23:37 2025 +0100

    related tdf#165180 oox: dateCompatibility not usable in LO
    
    This patch will be needed in order to round-trip
    the Excel 2010+ filter (ISOIEC_29500_2008).
    We can't use dateCompatibility because
    we don't have a "strict xml" filter.
    
    I've only triple checked this,
    so I can't be sure that I've got this right.
    
    WorkbookSettings::getNullDate is mostly dead code.
    
    getOoxFilter().getVersion() == oox::core::ISOIEC_29500_2008
    can only be true when the import filter is
        Calc Office Open XML Spreadsheet
    but that never happens because filterdetect.cxx
        if( rContentType == u"...spreadsheetml.sheet.main+xml")
            returns "MS Excel 2007 XML"_ustr;
    and calc_MS_Excel_2007_XML.xcu doesn't define
        <prop oor:name="FileFormatVersion"/>
    so it is considered to be a zero, which means that
         mxImpl->meVersion = OoxmlVersion( 0 );
    which is oox::core::ECMA_376_1ST_EDITION
    
    So getVersion for XLSX will never equal ISOIEC_29500_2008
    and thus the code this patch deletes has never been executed.
    
    Plus, our code was wrong. dateCompatibility only briefly
    made it into the ISO transitional standards before it disappeared.
    > mstahl:6:35 AM  we are puzzled by an attribute dateCompatibility
    > that is written by Calc since a commit
    > "Merged ooxml-sc-page-date.diff from ooo-build"
    > and was added to ECMA-376 3rd ed.
    > then removed (without explanation) from ECMA-376 4th ed.
    
    Excel only creates dateCompatibility when saving as "Strict Open XML",
    but we don't support OOXMLVariant::ISO_Strict.
    It seems to be ignored by Excel for non-strict formats.
    
    Plus, it wouldn't be needed by LO.
    Excel does not correctly display dates prior to Mar 1, 1900
    because it uses the old Lotus logic that treats
    1900 as a leap year, which it isn't.
    dateCompatibility="0" seems designed to tell Excel
    to consider Feb 29 1900 as an invalid date.
    LO never treats 1900 as a leap year (so no Feb 29, 1900),
    so our (accurate) dates do not match Excel.
    (That isn't a big deal because Excel starts at Jan 1 1900
     and is only wrong for the first two months,
     so we only don't match for the first 2 months of 1900.)
    
    Change-Id: I19ca19334e1f13da010bf09d4c5d9a32aea3a091
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194969
    Reviewed-by: Justin Luth <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 5f9d0cf0ce3a9b06138bbab62fcd3e6c89c9e339)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195117
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sc/source/filter/oox/workbooksettings.cxx 
b/sc/source/filter/oox/workbooksettings.cxx
index bb7269d9702f..2308c644e6fa 100644
--- a/sc/source/filter/oox/workbooksettings.cxx
+++ b/sc/source/filter/oox/workbooksettings.cxx
@@ -269,18 +269,18 @@ sal_Int16 WorkbookSettings::getApiShowObjectMode() const
 
 css::util::Date const & WorkbookSettings::getNullDate() const
 {
-    static const css::util::Date saDate1900                 ( 30, 12, 1899 );
-    static const css::util::Date saDate1904                 ( 1, 1, 1904 );
-    static const css::util::Date saDateBackCompatibility1900( 31, 12, 1899 );
+    // Excel (inacurrately) treats Feb 29, 1900 as a valid date (for 
compatibility with Lotus).
+    // AFAICS, only Strict .xlsx treats that date as invalid
+    // (regardless of whether dateCompatibility="0" or "1").
+    // Thus the only purpose of dateCompatibility="1" is to determine the 
oldest recognizable date
+    // which will be Jan 1 1904 if date1904="true", otherwise it will be Jan 1 
1900.
 
-    if( getOoxFilter().getVersion() == oox::core::ISOIEC_29500_2008 )
-    {
-        if( !maBookSettings.mbDateCompatibility )
-            return saDate1900;
+    // LO never treats 1900 as a leap year (so we never match Excel's first 
two months of 1900),
+    // and doesn't have an earliest recognizable date limitation.
+    // The day-early null date of Dec 30 1899 takes care of the extra leap-day 
that Excel inserts.
 
-        return maBookSettings.mbDateMode1904 ? saDate1904 :
-                                               saDateBackCompatibility1900;
-    }
+    static const css::util::Date saDate1900                 ( 30, 12, 1899 );
+    static const css::util::Date saDate1904                 ( 1, 1, 1904 );
 
     return maBookSettings.mbDateMode1904 ? saDate1904 : saDate1900;
 }

Reply via email to