summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-12-18 22:59:35 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-12-20 02:49:29 +0100
commit31eee6b372539f0f1ccb82d9a8012e878d498d56 (patch)
treeccba9b0c1da368fbec6ca909336830c14ec679bf
parent1e65f0176a9243274971321ffa5b6462130904ed (diff)
handle last week/next week betweek different years, fdo#58340
-rw-r--r--sc/source/core/data/conditio.cxx34
1 files changed, 25 insertions, 9 deletions
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 2b58f333b196..3dcc3be53f9a 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -1684,24 +1684,40 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const
return true;
break;
case condformat::LASTWEEK:
- if( rActDate.GetYear() == aCellDate.GetYear() )
+ if( rActDate.GetDayOfWeek() != SUNDAY )
{
- if( rActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) + 1 )
- return true;
+ Date aBegin(rActDate - 8 - static_cast<long>(rActDate.GetDayOfWeek()));
+ Date aEnd(rActDate - 2 -static_cast<long>(rActDate.GetDayOfWeek()));
+ return aCellDate.IsBetween( aBegin, aEnd );
+ }
+ else
+ {
+ Date aBegin(rActDate - 8);
+ Date aEnd(rActDate - 1);
+ return aCellDate.IsBetween( aBegin, aEnd );
}
break;
case condformat::THISWEEK:
- if( rActDate.GetYear() == aCellDate.GetYear() )
+ if( rActDate.GetDayOfWeek() != SUNDAY )
{
- if( rActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) )
- return true;
+ Date aBegin(rActDate - 1 - static_cast<long>(rActDate.GetDayOfWeek()));
+ Date aEnd(rActDate + 5 - static_cast<long>(rActDate.GetDayOfWeek()));
+ return aCellDate.IsBetween( aBegin, aEnd );
+ }
+ else
+ {
+ Date aEnd( rActDate + 6);
+ return aCellDate.IsBetween( rActDate, aEnd );
}
break;
case condformat::NEXTWEEK:
- if( rActDate.GetYear() == aCellDate.GetYear() )
+ if( rActDate.GetDayOfWeek() != SUNDAY )
{
- if( rActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) - 1 )
- return true;
+ return aCellDate.IsBetween( rActDate + 6 - static_cast<long>(rActDate.GetDayOfWeek()), rActDate + 12 - static_cast<long>(rActDate.GetDayOfWeek()) );
+ }
+ else
+ {
+ return aCellDate.IsBetween( rActDate + 7, rActDate + 13 );
}
break;
case condformat::LASTMONTH: