Kaydet (Commit) 8232eaf9 authored tarafından Eike Rathke's avatar Eike Rathke

ImplDateIncrementYear: handle February 29

Change-Id: I1120950f1161e51591701368229844f6a5344eeb
üst eea4a30a
...@@ -1372,6 +1372,7 @@ static void ImplDateIncrementYear( Date& rDate, sal_Bool bUp ) ...@@ -1372,6 +1372,7 @@ static void ImplDateIncrementYear( Date& rDate, sal_Bool bUp )
DateFormatter::ExpandCentury( rDate ); DateFormatter::ExpandCentury( rDate );
sal_uInt16 nYear = rDate.GetYear(); sal_uInt16 nYear = rDate.GetYear();
sal_uInt16 nMonth = rDate.GetMonth();
if ( bUp ) if ( bUp )
{ {
if ( nYear < 9999 ) if ( nYear < 9999 )
...@@ -1382,6 +1383,20 @@ static void ImplDateIncrementYear( Date& rDate, sal_Bool bUp ) ...@@ -1382,6 +1383,20 @@ static void ImplDateIncrementYear( Date& rDate, sal_Bool bUp )
if ( nYear > 0 ) if ( nYear > 0 )
rDate.SetYear( nYear - 1 ); rDate.SetYear( nYear - 1 );
} }
if (nMonth == 2)
{
// Handle February 29 from leap year to non-leap year.
sal_uInt16 nDay = rDate.GetDay();
if (nDay > 28)
{
// The check would not be necessary if it was guaranteed that the
// date was valid before and actually was a leap year,
// de-/incrementing a leap year with 29 always results in 28.
sal_uInt16 nDaysInMonth = Date::GetDaysInMonth( nMonth, rDate.GetYear());
if (nDay > nDaysInMonth)
rDate.SetDay( nDaysInMonth);
}
}
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
......
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