From 8189d815641c583b5506d482f0b4f1ab47924f6a Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Mon, 9 May 2022 16:09:21 +0100 Subject: 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 --- basic/source/runtime/methods.cxx | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'basic') 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( 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(aDate); - nDays -= 2; // standardize: 1.1.1900 => 0.0 aRefDate.AddDays( nDays ); sal_Int16 nRet = static_cast( 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(aDate); - nDays -= 2; // standardize: 1.1.1900 => 0.0 + Date aRefDate(1899'12'30); + sal_Int32 nDays = static_cast(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(nDiffDays); + rdRet = GetDayDiff(aCurDate); return true; } -- cgit