basic/source/runtime/methods.cxx |   33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

New commits:
commit 8189d815641c583b5506d482f0b4f1ab47924f6a
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon May 9 16:09:21 2022 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon May 9 19:04:46 2022 +0200

    Use usual 1899-12-30 base Date in Basic
    
    It matches VBA, has an optimization in the code, and doesn't
    need any additional "-2" hackery.
    
    Change-Id: I4b90674ae643788eda5ce618b4c42e2cc045ec04
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134060
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index e86ac2d64c63..2ebae2751157 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -133,7 +133,7 @@ static void FilterWhiteSpace( OUString& rStr )
     rStr = aRet.makeStringAndClear();
 }
 
-static tools::Long GetDayDiff( const Date& rDate );
+static sal_Int32 GetDayDiff(const Date& rDate) { return rDate - 
Date(1899'12'30); }
 
 static const CharClass& GetCharClass()
 {
@@ -1681,9 +1681,8 @@ void SbRtl_Val(StarBASIC *, SbxArray & rPar, bool)
 // Helper functions for date conversion
 sal_Int16 implGetDateDay( double aDate )
 {
-    aDate -= 2.0; // standardize: 1.1.1900 => 0.0
     aDate = floor( aDate );
-    Date aRefDate( 1, 1, 1900 );
+    Date aRefDate(1899'12'30);
     aRefDate.AddDays( aDate );
 
     sal_Int16 nRet = static_cast<sal_Int16>( aRefDate.GetDay() );
@@ -1692,9 +1691,8 @@ sal_Int16 implGetDateDay( double aDate )
 
 sal_Int16 implGetDateMonth( double aDate )
 {
-    Date aRefDate( 1,1,1900 );
+    Date aRefDate(1899'12'30);
     sal_Int32 nDays = static_cast<sal_Int32>(aDate);
-    nDays -= 2; // standardize: 1.1.1900 => 0.0
     aRefDate.AddDays( nDays );
     sal_Int16 nRet = static_cast<sal_Int16>( aRefDate.GetMonth() );
     return nRet;
@@ -4653,28 +4651,10 @@ void SbRtl_Partition(StarBASIC *, SbxArray & rPar, bool)
 
 #endif
 
-static tools::Long GetDayDiff( const Date& rDate )
-{
-    Date aRefDate( 1,1,1900 );
-    tools::Long nDiffDays;
-    if ( aRefDate > rDate )
-    {
-        nDiffDays = aRefDate - rDate;
-        nDiffDays *= -1;
-    }
-    else
-    {
-        nDiffDays = rDate - aRefDate;
-    }
-    nDiffDays += 2; // adjustment VisualBasic: 1.Jan.1900 == 2
-    return nDiffDays;
-}
-
 sal_Int16 implGetDateYear( double aDate )
 {
-    Date aRefDate( 1,1,1900 );
-    tools::Long nDays = static_cast<tools::Long>(aDate);
-    nDays -= 2; // standardize: 1.1.1900 => 0.0
+    Date aRefDate(1899'12'30);
+    sal_Int32 nDays = static_cast<sal_Int32>(aDate);
     aRefDate.AddDays( nDays );
     sal_Int16 nRet = aRefDate.GetYear();
     return nRet;
@@ -4786,8 +4766,7 @@ bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, 
sal_Int16 nDay,
         }
     }
 
-    tools::Long nDiffDays = GetDayDiff( aCurDate );
-    rdRet = static_cast<double>(nDiffDays);
+    rdRet = GetDayDiff(aCurDate);
     return true;
 }
 

Reply via email to