diff options
author | Eike Rathke <erack@redhat.com> | 2013-05-17 17:53:47 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-05-17 17:55:28 +0200 |
commit | 8232eaf93f7f2837d049175a521ef05d68b12214 (patch) | |
tree | 1cb94fb986cf9169719b8d195fc71d9afc21dfbe | |
parent | eea4a30a4332b92b5534d3d3dc0e6152108ed670 (diff) |
ImplDateIncrementYear: handle February 29
Change-Id: I1120950f1161e51591701368229844f6a5344eeb
-rw-r--r-- | vcl/source/control/field2.cxx | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx index d5dfd0715144..da08f7dfc383 100644 --- a/vcl/source/control/field2.cxx +++ b/vcl/source/control/field2.cxx @@ -1372,6 +1372,7 @@ static void ImplDateIncrementYear( Date& rDate, sal_Bool bUp ) DateFormatter::ExpandCentury( rDate ); sal_uInt16 nYear = rDate.GetYear(); + sal_uInt16 nMonth = rDate.GetMonth(); if ( bUp ) { if ( nYear < 9999 ) @@ -1382,6 +1383,20 @@ static void ImplDateIncrementYear( Date& rDate, sal_Bool bUp ) if ( nYear > 0 ) 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); + } + } } // ----------------------------------------------------------------------- |