From 9d2fdc5e5649661c9927dd49d32d06d61d58c4d7 Mon Sep 17 00:00:00 2001 From: epsdky Date: Thu, 4 Jun 2015 07:13:57 +1000 Subject: [PATCH] Fix for the recurring appointment bug in Calendar This fixes a recurring appointment bug in the Calendar, which caused both missing appointments and appointments with wrong date. It effected these recurring appointments... every (1st, 2nd, ...) (Mon, Tue ...) of the month set on start date 29, 30, or 31. Example - setting a recurring appointment for every last Friday on the 31/12/2014 would result in the appointment for Feb going missing. If the appointment was set for every 2nd month, then all dates were wrong after December. --- .../main/calendar/modules/PostCalendar/pnuserapi.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/interface/main/calendar/modules/PostCalendar/pnuserapi.php b/interface/main/calendar/modules/PostCalendar/pnuserapi.php index b10f63123..d4dc2ec8b 100644 --- a/interface/main/calendar/modules/PostCalendar/pnuserapi.php +++ b/interface/main/calendar/modules/PostCalendar/pnuserapi.php @@ -1446,8 +1446,21 @@ function calculateEvents($days,$events,$viewtype) { //============================================================== $nm = $esM; $ny = $esY; $nd = $esD; // make us current + // + // $nd at some time will be 29, 30 or 31 which will cause overflow in mktime, + // so need to use $this01 instead. + // more detailed explanation of this bug fix is: + // Lines 1462-1465 and 1497 are only concerned with year and month. + // Only the year and month elements of the value of $occurance calculated + // in the 1463 and 1497 lines (mktime) are ever inputs for further processing + // (and only in line 1471). The day component never becomes an input for anything + // at all (except explode function). So it is irrelevant. (Also the only values of + // $nd that are important to lines 1463 and 1497 are 29, 30 and 30 since these will + // cause an overflow to the next month) + $this01 = '01'; + while($ny < $cy) { - $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny)); + $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$this01,$ny)); list($ny,$nm,$nd) = explode('-',$occurance); } @@ -1481,7 +1494,7 @@ function calculateEvents($days,$events,$viewtype) { $days[$occurance]['blocks'][$gbt][$occurance][] = $event; } } - $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny)); + $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$this01,$ny)); list($ny,$nm,$nd) = explode('-',$occurance); } -- 2.11.4.GIT