Kaydet (Commit) 94a52f9f authored tarafından Damjan Jovanovic's avatar Damjan Jovanovic Kaydeden (comit) Caolán McNamara

Resolves: #i117989# Basic functions return wrong results for dates <1900-1-1

Also extended our spreadsheeet test to search through more columns, open spreadsheets
with macros enabled, and added a test for the the Year(), Month(), Day(), Hour(),
Minute(), and Second() functions comparing Calc's formulas vs StarBasic's runtime functions.

Found-by: villeroy
Patch-by: Damjan Jovanovic

(cherry picked from commit a6849326)

Change-Id: I8f2115c623a1d35db5b7fc8184a9118c3eca6fcd
üst cf4839cf
...@@ -1820,17 +1820,9 @@ RTLFUNC(Val) ...@@ -1820,17 +1820,9 @@ RTLFUNC(Val)
sal_Int16 implGetDateDay( double aDate ) sal_Int16 implGetDateDay( double aDate )
{ {
aDate -= 2.0; // standardize: 1.1.1900 => 0.0 aDate -= 2.0; // standardize: 1.1.1900 => 0.0
aDate = floor( aDate );
Date aRefDate( 1, 1, 1900 ); Date aRefDate( 1, 1, 1900 );
if ( aDate >= 0.0 ) aRefDate += static_cast<long>(aDate);
{
aDate = floor( aDate );
aRefDate += static_cast<long>(aDate);
}
else
{
aDate = ceil( aDate );
aRefDate -= static_cast<long>(-1.0 * aDate);
}
sal_Int16 nRet = (sal_Int16)( aRefDate.GetDay() ); sal_Int16 nRet = (sal_Int16)( aRefDate.GetDay() );
return nRet; return nRet;
...@@ -2270,10 +2262,6 @@ RTLFUNC(Year) ...@@ -2270,10 +2262,6 @@ RTLFUNC(Year)
sal_Int16 implGetHour( double dDate ) sal_Int16 implGetHour( double dDate )
{ {
if( dDate < 0.0 )
{
dDate *= -1.0;
}
double nFrac = dDate - floor( dDate ); double nFrac = dDate - floor( dDate );
nFrac *= 86400.0; nFrac *= 86400.0;
sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5); sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5);
...@@ -2333,10 +2321,6 @@ RTLFUNC(Month) ...@@ -2333,10 +2321,6 @@ RTLFUNC(Month)
sal_Int16 implGetSecond( double dDate ) sal_Int16 implGetSecond( double dDate )
{ {
if( dDate < 0.0 )
{
dDate *= -1.0;
}
double nFrac = dDate - floor( dDate ); double nFrac = dDate - floor( dDate );
nFrac *= 86400.0; nFrac *= 86400.0;
sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5); sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5);
...@@ -5016,10 +5000,6 @@ bool implDateTimeSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, ...@@ -5016,10 +5000,6 @@ bool implDateTimeSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay,
sal_Int16 implGetMinute( double dDate ) sal_Int16 implGetMinute( double dDate )
{ {
if( dDate < 0.0 )
{
dDate *= -1.0;
}
double nFrac = dDate - floor( dDate ); double nFrac = dDate - floor( dDate );
nFrac *= 86400.0; nFrac *= 86400.0;
sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5); sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment