Add basic support for RDATE recurrence properties (#2886).
This only uses these values as a fall-back if no RRULE is defined but not in combination with it.
This commit is contained in:
parent
79ae6282f8
commit
1f6729eb14
3 changed files with 54 additions and 1 deletions
|
@ -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 = '';
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue