diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index ddaa4273..092a2247 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -1439,6 +1439,23 @@ class calendar extends rcube_plugin */ private function _recurrence_text($rrule) { + // derive missing FREQ and INTERVAL from RDATE list + if (empty($rrule['FREQ']) && !empty($rrule['RDATE'])) { + $first = $rrule['RDATE'][0]; + $second = $rrule['RDATE'][1]; + if (is_a($first, 'DateTime') && is_a($second, 'DateTime')) { + $diff = $first->diff($second); + foreach (array('y' => 'YEARLY', 'm' => 'MONTHLY', 'd' => 'DAILY') as $k => $freq) { + if ($diff->$k != 0) { + $rrule['FREQ'] = $freq; + $rrule['INTERVAL'] = $diff->$k; + break; + } + } + } + $rrule['UNTIL'] = end($rrule['RDATE']); + } + // TODO: finish this $freq = sprintf('%s %d ', $this->gettext('every'), $rrule['INTERVAL']); $details = ''; diff --git a/plugins/calendar/lib/Horde_Date_Recurrence.php b/plugins/calendar/lib/Horde_Date_Recurrence.php index 81f0857d..35f884c7 100644 --- a/plugins/calendar/lib/Horde_Date_Recurrence.php +++ b/plugins/calendar/lib/Horde_Date_Recurrence.php @@ -126,6 +126,13 @@ class Horde_Date_Recurrence */ public $recurMonths = array(); + /** + * RDATE recurrence values + * + * @var array + */ + public $rdates = array(); + /** * All the exceptions from recurrence for this event. * @@ -427,7 +434,7 @@ class Horde_Date_Recurrence return clone $this->start; } - if ($this->recurInterval == 0) { + if ($this->recurInterval == 0 && empty($this->rdates)) { return false; } @@ -779,6 +786,19 @@ class Horde_Date_Recurrence return $next; } + // fall-back to RDATE properties + if (!empty($this->rdates)) { + $next = clone $this->start; + foreach ($this->rdates as $rdate) { + $next->year = $rdate->year; + $next->month = $rdate->month; + $next->mday = $rdate->mday; + if ($next->compareDateTime($after) > 0) { + return $next; + } + } + } + // We didn't find anything, the recurType was bad, or something else // went wrong - return false. return false; @@ -834,6 +854,18 @@ class Horde_Date_Recurrence return false; } + /** + * Adds an absolute recurrence date. + * + * @param integer $year The year of the instance. + * @param integer $month The month of the instance. + * @param integer $mday The day of the month of the instance. + */ + public function addRDate($year, $month, $mday) + { + $this->rdates[] = new Horde_Date($year, $month, $mday); + } + /** * Adds an exception to a recurring event. * diff --git a/plugins/calendar/lib/calendar_recurrence.php b/plugins/calendar/lib/calendar_recurrence.php index d4a36412..5c218523 100644 --- a/plugins/calendar/lib/calendar_recurrence.php +++ b/plugins/calendar/lib/calendar_recurrence.php @@ -60,6 +60,10 @@ class calendar_recurrence foreach ($event['recurrence']['EXDATE'] as $exdate) $this->engine->addException($exdate->format('Y'), $exdate->format('n'), $exdate->format('j')); } + if (is_array($event['recurrence']['RDATE'])) { + foreach ($event['recurrence']['RDATE'] as $rdate) + $this->engine->addRDate($rdate->format('Y'), $rdate->format('n'), $rdate->format('j')); + } } /**