Fix bug 386516 - Monthly repeating event on last day of month occurs on wrong dates. r=decathlona=philipp
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 27 Oct 2011 10:44:53 +0200
changeset 8955 e05b354769be4aad6a228341929cccb641222542
parent 8954 47af4afca66a7b1130676ad673fc7a8db69d9b08
child 8956 8898520a1258e32a4883b6fd71453d2255b12d3e
push id207
push usermozilla@kewis.ch
push dateThu, 27 Oct 2011 13:43:58 +0000
treeherdercomm-beta@359d0ea7f24d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdecathlona
bugs386516
Fix bug 386516 - Monthly repeating event on last day of month occurs on wrong dates. r=decathlona=philipp
calendar/libical/src/libical/icalrecur.c
--- a/calendar/libical/src/libical/icalrecur.c
+++ b/calendar/libical/src/libical/icalrecur.c
@@ -1067,17 +1067,24 @@ icalrecur_iterator* icalrecur_iterator_n
 
 	if(impl->last.day > days_in_month || impl->last.day == 0){
 	    icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
             free(impl);
             return 0;
 	}
 	
     } else if (has_by_data(impl,BY_MONTH_DAY)) {
-	impl->last = icaltime_normalize(impl->last);
+        // setup_defaults sets the day to -1 for negative BYMONTHDAY values,
+        // so make sure to re-calculate with days_in_month
+        if (impl->last.day < 0) {
+            int days_in_month =
+                    icaltime_days_in_month(impl->last.month, impl->last.year);
+            impl->last.day = days_in_month + impl->last.day + 1;
+        }
+        impl->last = icaltime_normalize(impl->last);
     }
 
 
 
     return impl;
 }