[dev] [kronolith-patch] end of month recurrence

Francois Marier francois at nit.ca
Mon Aug 9 12:30:17 PDT 2004


Here's a patch for Kronolith that helps with events that are supposed
to recur on the last day of each month.

If an event is set to recur on the 31st of each month, it will show up
on the 30th of the months that don't have 31 days (or 28/29 for
February).

Francois
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/kronolith/lib/Driver.php kronolith/lib/Driver.php
--- ../build/kronolith/lib/Driver.php	Thu Aug  5 17:06:32 2004
+++ kronolith/lib/Driver.php	Thu Aug  5 17:07:49 2004
@@ -209,7 +209,20 @@ class Kronolith_Driver {
             $offset = (($offset + $event->recurInterval - 1) / $event->recurInterval) * $event->recurInterval;
 
             $start->month += $offset;
+
+            // Fix the date but keep the same mday even if it's wrong,
+            // it will be fixed in the next step.
+            $old_mday = $start->mday;
+            $start->mday = 1;
             $start->correct();
+            $start->mday = $old_mday;
+
+            // Allow events set to the 29th, 30th, 31st of each month to occur
+            // on the last day of the months that don't have enough days
+            $daysInMonth = Date_Calc::daysInMonth($start->month, $start->year);
+            if ($start->mday > $daysInMonth) {
+                $start->mday = $daysInMonth;
+            }
 
             // Bail if we've gone past the end of recurrence.
             if (Kronolith::compareDates($event->recurEnd, $start) < 0) {


More information about the dev mailing list