chart2/source/tools/NumberFormatterWrapper.cxx |   25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

New commits:
commit e3788eb3c199367dd3321b52281794a0baf61a17
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Sat Aug 6 20:55:33 2022 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Aug 8 12:35:01 2022 +0200

    crashtesting: null date assert seen on loading forum-fr-25994.ods
    
    presumably part of this problem is since:
    
    commit 22c7da0ca5438b69165609db2a1ef219aa167dc2
    Date:   Wed Mar 19 04:50:20 2014 +0100
    
        the type in the Any is a util::Date and not a DateTime, fdo#74549
    
    and we also have...
    
        rOutProperties.emplace_back( "NullDate",
                      PROP_DOCUMENT_NULL_DATE,
                      ::cppu::UnoType<css::util::DateTime>::get(),
                      beans::PropertyAttribute::MAYBEVOID );
    
    which has DateTime and not Date, but we can get this set as either Date and
    DateTime, so just accept both.
    
    Change-Id: If77af5bb74755d2196527112665facf27a4d1403
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137821
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/chart2/source/tools/NumberFormatterWrapper.cxx 
b/chart2/source/tools/NumberFormatterWrapper.cxx
index d6e704d145d6..e00df1fae04e 100644
--- a/chart2/source/tools/NumberFormatterWrapper.cxx
+++ b/chart2/source/tools/NumberFormatterWrapper.cxx
@@ -66,12 +66,31 @@ NumberFormatterWrapper::~NumberFormatterWrapper()
 {
 }
 
+namespace
+{
+    bool getDate(const css::uno::Any& rAny, util::Date& rDate)
+    {
+        if (rAny >>= rDate)
+            return true;
+        util::DateTime aUtilDateTime;
+        if (rAny >>= aUtilDateTime)
+        {
+            rDate.Day = aUtilDateTime.Day;
+            rDate.Month = aUtilDateTime.Month;
+            rDate.Year = aUtilDateTime.Year;
+            return true;
+        }
+        SAL_WARN("chart2.tools", "neither a util::Date nor a util::DateTime");
+        return false;
+    }
+}
+
 Date NumberFormatterWrapper::getNullDate() const
 {
     Date aRet(30,12,1899);
 
     util::Date aUtilDate;
-    if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) )
+    if (m_aNullDate.hasValue() && getDate(m_aNullDate, aUtilDate))
     {
         aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year);
     }
@@ -102,8 +121,8 @@ OUString NumberFormatterWrapper::getFormattedString( 
sal_Int32 nNumberFormatKey,
         nMonth = rDate.GetMonth();
         nDay = rDate.GetDay();
         util::Date aNewNullDate;
-        m_aNullDate >>= aNewNullDate;
-        
m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
+        if (getDate(m_aNullDate, aNewNullDate))
+            
m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
     }
     // tdf#130969: use UNLIMITED_PRECISION in case of GENERAL Number Format
     if( m_pNumberFormatter->GetStandardPrec() != 
SvNumberFormatter::UNLIMITED_PRECISION )

Reply via email to