Changeset View
Changeset View
Standalone View
Standalone View
plugins/libcalendaring/lib/libcalendaring_recurrence.php
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | class libcalendaring_recurrence | ||||
{ | { | ||||
$this->recurrence = $recurrence; | $this->recurrence = $recurrence; | ||||
$this->engine = new Horde_Date_Recurrence($start); | $this->engine = new Horde_Date_Recurrence($start); | ||||
$this->engine->fromRRule20(libcalendaring::to_rrule($recurrence)); | $this->engine->fromRRule20(libcalendaring::to_rrule($recurrence)); | ||||
$this->set_start($start); | $this->set_start($start); | ||||
if (is_array($recurrence['EXDATE'])) { | if (!empty($recurrence['EXDATE'])) { | ||||
foreach ($recurrence['EXDATE'] as $exdate) { | foreach ((array) $recurrence['EXDATE'] as $exdate) { | ||||
if (is_a($exdate, 'DateTime')) { | if (is_a($exdate, 'DateTime')) { | ||||
$this->engine->addException($exdate->format('Y'), $exdate->format('n'), $exdate->format('j')); | $this->engine->addException($exdate->format('Y'), $exdate->format('n'), $exdate->format('j')); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (is_array($recurrence['RDATE'])) { | if (!empty($recurrence['RDATE'])) { | ||||
foreach ($recurrence['RDATE'] as $rdate) { | foreach ((array) $recurrence['RDATE'] as $rdate) { | ||||
if (is_a($rdate, 'DateTime')) { | if (is_a($rdate, 'DateTime')) { | ||||
$this->engine->addRDate($rdate->format('Y'), $rdate->format('n'), $rdate->format('j')); | $this->engine->addRDate($rdate->format('Y'), $rdate->format('n'), $rdate->format('j')); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | class libcalendaring_recurrence | ||||
/** | /** | ||||
* Find date/time of the first occurrence (excluding start date) | * Find date/time of the first occurrence (excluding start date) | ||||
*/ | */ | ||||
public function first_occurrence() | public function first_occurrence() | ||||
{ | { | ||||
$start = clone $this->start; | $start = clone $this->start; | ||||
$orig_start = clone $this->start; | $orig_start = clone $this->start; | ||||
$r = $this->recurrence; | $r = $this->recurrence; | ||||
$interval = intval($r['INTERVAL'] ?: 1); | $interval = !empty($r['INTERVAL']) ? intval($r['INTERVAL']) : 1; | ||||
$frequency = isset($this->recurrence['FREQ']) ? $this->recurrence['FREQ'] : null; | |||||
switch ($this->recurrence['FREQ']) { | switch ($frequency) { | ||||
case 'WEEKLY': | case 'WEEKLY': | ||||
if (empty($this->recurrence['BYDAY'])) { | if (empty($this->recurrence['BYDAY'])) { | ||||
return $start; | return $start; | ||||
} | } | ||||
$start->sub(new DateInterval("P{$interval}W")); | $start->sub(new DateInterval("P{$interval}W")); | ||||
break; | break; | ||||
Show All 14 Lines | public function first_occurrence() | ||||
break; | break; | ||||
default: | default: | ||||
return $start; | return $start; | ||||
} | } | ||||
$r = $this->recurrence; | $r = $this->recurrence; | ||||
$r['INTERVAL'] = $interval; | $r['INTERVAL'] = $interval; | ||||
if ($r['COUNT']) { | if (!empty($r['COUNT'])) { | ||||
// Increase count so we do not stop the loop to early | // Increase count so we do not stop the loop to early | ||||
$r['COUNT'] += 100; | $r['COUNT'] += 100; | ||||
} | } | ||||
// Create recurrence that starts in the past | // Create recurrence that starts in the past | ||||
$recurrence = new self($this->lib); | $recurrence = new self($this->lib); | ||||
$recurrence->init($r, $start); | $recurrence->init($r, $start); | ||||
Show All 30 Lines |