[Libreoffice-commits] core.git: vcl/source

Eike Rathke erack at redhat.com
Fri May 17 08:55:51 PDT 2013


 vcl/source/control/field2.cxx |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

New commits:
commit 8232eaf93f7f2837d049175a521ef05d68b12214
Author: Eike Rathke <erack at redhat.com>
Date:   Fri May 17 17:53:47 2013 +0200

    ImplDateIncrementYear: handle February 29
    
    Change-Id: I1120950f1161e51591701368229844f6a5344eeb

diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx
index d5dfd07..da08f7d 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);
+        }
+    }
 }
 
 // -----------------------------------------------------------------------


More information about the Libreoffice-commits mailing list