From f1c07977809ce3221286d53e99f0d91145b1166f Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 25 Apr 2019 11:24:09 +0200 Subject: Revert "update composer libs" This reverts commit e779335d060b3a51d6a144d23af4097ae6801473 --- vendor/sabre/vobject/lib/Recur/EventIterator.php | 103 ++++++++++++++--------- 1 file changed, 65 insertions(+), 38 deletions(-) (limited to 'vendor/sabre/vobject/lib/Recur/EventIterator.php') diff --git a/vendor/sabre/vobject/lib/Recur/EventIterator.php b/vendor/sabre/vobject/lib/Recur/EventIterator.php index 135ecf00e..d313305a0 100644 --- a/vendor/sabre/vobject/lib/Recur/EventIterator.php +++ b/vendor/sabre/vobject/lib/Recur/EventIterator.php @@ -58,8 +58,8 @@ use Sabre\VObject\Settings; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class EventIterator implements \Iterator -{ +class EventIterator implements \Iterator { + /** * Reference timeZone for floating dates and times. * @@ -89,12 +89,12 @@ class EventIterator implements \Iterator * The $uid parameter is only required for the first method. * * @param Component|array $input - * @param string|null $uid - * @param DateTimeZone $timeZone reference timezone for floating dates and - * times + * @param string|null $uid + * @param DateTimeZone $timeZone Reference timezone for floating dates and + * times. */ - public function __construct($input, $uid = null, DateTimeZone $timeZone = null) - { + function __construct($input, $uid = null, DateTimeZone $timeZone = null) { + if (is_null($timeZone)) { $timeZone = new DateTimeZone('UTC'); } @@ -107,7 +107,7 @@ class EventIterator implements \Iterator $events = [$input]; } else { // Calendar + UID mode. - $uid = (string) $uid; + $uid = (string)$uid; if (!$uid) { throw new InvalidArgumentException('The UID argument is required when a VCALENDAR is passed to this constructor'); } @@ -115,17 +115,24 @@ class EventIterator implements \Iterator throw new InvalidArgumentException('No events found in this calendar'); } $events = $input->getByUID($uid); + } foreach ($events as $vevent) { + if (!isset($vevent->{'RECURRENCE-ID'})) { + $this->masterEvent = $vevent; + } else { + $this->exceptions[ $vevent->{'RECURRENCE-ID'}->getDateTime($this->timeZone)->getTimeStamp() ] = true; $this->overriddenEvents[] = $vevent; + } + } if (!$this->masterEvent) { @@ -136,7 +143,7 @@ class EventIterator implements \Iterator // event and use that instead. This may not always give the // desired result. if (!count($this->overriddenEvents)) { - throw new InvalidArgumentException('This VCALENDAR did not have an event with UID: '.$uid); + throw new InvalidArgumentException('This VCALENDAR did not have an event with UID: ' . $uid); } $this->masterEvent = array_shift($this->overriddenEvents); } @@ -145,11 +152,15 @@ class EventIterator implements \Iterator $this->allDay = !$this->masterEvent->DTSTART->hasTime(); if (isset($this->masterEvent->EXDATE)) { + foreach ($this->masterEvent->EXDATE as $exDate) { + foreach ($exDate->getDateTimes($this->timeZone) as $dt) { $this->exceptions[$dt->getTimeStamp()] = true; } + } + } if (isset($this->masterEvent->DTEND)) { @@ -180,7 +191,7 @@ class EventIterator implements \Iterator } else { $this->recurIterator = new RRuleIterator( [ - 'FREQ' => 'DAILY', + 'FREQ' => 'DAILY', 'COUNT' => 1, ], $this->startDate @@ -191,6 +202,7 @@ class EventIterator implements \Iterator if (!$this->valid()) { throw new NoInstancesException('This recurrence rule does not generate any valid instances'); } + } /** @@ -198,11 +210,12 @@ class EventIterator implements \Iterator * * @return DateTimeImmutable */ - public function current() - { + function current() { + if ($this->currentDate) { return clone $this->currentDate; } + } /** @@ -211,11 +224,12 @@ class EventIterator implements \Iterator * * @return DateTimeImmutable */ - public function getDtStart() - { + function getDtStart() { + if ($this->currentDate) { return clone $this->currentDate; } + } /** @@ -224,26 +238,26 @@ class EventIterator implements \Iterator * * @return DateTimeImmutable */ - public function getDtEnd() - { + function getDtEnd() { + if (!$this->valid()) { return; } $end = clone $this->currentDate; + return $end->modify('+' . $this->eventDuration . ' seconds'); - return $end->modify('+'.$this->eventDuration.' seconds'); } /** * Returns a VEVENT for the current iterations of the event. * - * This VEVENT will have a recurrence id, and its DTSTART and DTEND + * This VEVENT will have a recurrence id, and it's DTSTART and DTEND * altered. * * @return VEvent */ - public function getEventObject() - { + function getEventObject() { + if ($this->currentOverriddenEvent) { return $this->currentOverriddenEvent; } @@ -270,8 +284,8 @@ class EventIterator implements \Iterator $recurid = clone $event->DTSTART; $recurid->name = 'RECURRENCE-ID'; $event->add($recurid); - return $event; + } /** @@ -281,10 +295,11 @@ class EventIterator implements \Iterator * * @return int */ - public function key() - { + function key() { + // The counter is always 1 ahead. return $this->counter - 1; + } /** @@ -293,20 +308,20 @@ class EventIterator implements \Iterator * * @return bool */ - public function valid() - { - if ($this->counter > Settings::$maxRecurrences && -1 !== Settings::$maxRecurrences) { - throw new MaxInstancesExceededException('Recurring events are only allowed to generate '.Settings::$maxRecurrences); + function valid() { + + if ($this->counter > Settings::$maxRecurrences && Settings::$maxRecurrences !== -1) { + throw new MaxInstancesExceededException('Recurring events are only allowed to generate ' . Settings::$maxRecurrences); } + return !!$this->currentDate; - return (bool) $this->currentDate; } /** * Sets the iterator back to the starting point. */ - public function rewind() - { + function rewind() { + $this->recurIterator->rewind(); // re-creating overridden event index. $index = []; @@ -323,15 +338,18 @@ class EventIterator implements \Iterator $this->currentDate = clone $this->startDate; $this->next(); + } /** * Advances the iterator with one step. + * + * @return void */ - public function next() - { + function next() { + $this->currentOverriddenEvent = null; - ++$this->counter; + $this->counter++; if ($this->nextDate) { // We had a stored value. $nextDate = $this->nextDate; @@ -348,11 +366,14 @@ class EventIterator implements \Iterator $nextDate = $this->recurIterator->current(); $this->recurIterator->next(); } while (isset($this->exceptions[$nextDate->getTimeStamp()])); + } + // $nextDate now contains what rrule thinks is the next one, but an // overridden event may cut ahead. if ($this->overriddenEventsIndex) { + $offsets = end($this->overriddenEventsIndex); $timestamp = key($this->overriddenEventsIndex); $offset = end($offsets); @@ -372,10 +393,13 @@ class EventIterator implements \Iterator // Exit point! return; + } + } $this->currentDate = $nextDate; + } /** @@ -383,11 +407,12 @@ class EventIterator implements \Iterator * * @param DateTimeInterface $dateTime */ - public function fastForward(DateTimeInterface $dateTime) - { + function fastForward(DateTimeInterface $dateTime) { + while ($this->valid() && $this->getDtEnd() <= $dateTime) { $this->next(); } + } /** @@ -395,9 +420,10 @@ class EventIterator implements \Iterator * * @return bool */ - public function isInfinite() - { + function isInfinite() { + return $this->recurIterator->isInfinite(); + } /** @@ -478,9 +504,10 @@ class EventIterator implements \Iterator protected $nextDate; /** - * The event that overwrites the current iteration. + * The event that overwrites the current iteration * * @var VEVENT */ protected $currentOverriddenEvent; + } -- cgit v1.2.3