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/RRuleIterator.php | 411 +++++++++++++---------- 1 file changed, 233 insertions(+), 178 deletions(-) (limited to 'vendor/sabre/vobject/lib/Recur/RRuleIterator.php') diff --git a/vendor/sabre/vobject/lib/Recur/RRuleIterator.php b/vendor/sabre/vobject/lib/Recur/RRuleIterator.php index 554507f19..dbea1155d 100644 --- a/vendor/sabre/vobject/lib/Recur/RRuleIterator.php +++ b/vendor/sabre/vobject/lib/Recur/RRuleIterator.php @@ -22,30 +22,29 @@ use Sabre\VObject\Property; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class RRuleIterator implements Iterator -{ +class RRuleIterator implements Iterator { + /** * Creates the Iterator. * - * @param string|array $rrule + * @param string|array $rrule * @param DateTimeInterface $start */ - public function __construct($rrule, DateTimeInterface $start) - { + function __construct($rrule, DateTimeInterface $start) { + $this->startDate = $start; $this->parseRRule($rrule); $this->currentDate = clone $this->startDate; + } /* Implementation of the Iterator interface {{{ */ - public function current() - { - if (!$this->valid()) { - return; - } + function current() { + if (!$this->valid()) return; return clone $this->currentDate; + } /** @@ -53,9 +52,10 @@ class RRuleIterator implements Iterator * * @return int */ - public function key() - { + function key() { + return $this->counter; + } /** @@ -65,53 +65,61 @@ class RRuleIterator implements Iterator * * @return bool */ - public function valid() - { + function valid() { + if (!is_null($this->count)) { return $this->counter < $this->count; } - return is_null($this->until) || $this->currentDate <= $this->until; + } /** * Resets the iterator. + * + * @return void */ - public function rewind() - { + function rewind() { + $this->currentDate = clone $this->startDate; $this->counter = 0; + } /** * Goes on to the next iteration. + * + * @return void */ - public function next() - { + function next() { + // Otherwise, we find the next event in the normal RRULE // sequence. switch ($this->frequency) { - case 'hourly': + + case 'hourly' : $this->nextHourly(); break; - case 'daily': + case 'daily' : $this->nextDaily(); break; - case 'weekly': + case 'weekly' : $this->nextWeekly(); break; - case 'monthly': + case 'monthly' : $this->nextMonthly(); break; - case 'yearly': + case 'yearly' : $this->nextYearly(); break; + } - ++$this->counter; + $this->counter++; + } /* End of Iterator implementation }}} */ @@ -121,9 +129,10 @@ class RRuleIterator implements Iterator * * @return bool */ - public function isInfinite() - { + function isInfinite() { + return !$this->count && !$this->until; + } /** @@ -131,12 +140,15 @@ class RRuleIterator implements Iterator * specified date. * * @param DateTimeInterface $dt + * + * @return void */ - public function fastForward(DateTimeInterface $dt) - { + function fastForward(DateTimeInterface $dt) { + while ($this->valid() && $this->currentDate < $dt) { $this->next(); } + } /** @@ -305,20 +317,24 @@ class RRuleIterator implements Iterator /** * Does the processing for advancing the iterator for hourly frequency. + * + * @return void */ - protected function nextHourly() - { - $this->currentDate = $this->currentDate->modify('+'.$this->interval.' hours'); + protected function nextHourly() { + + $this->currentDate = $this->currentDate->modify('+' . $this->interval . ' hours'); + } /** * Does the processing for advancing the iterator for daily frequency. + * + * @return void */ - protected function nextDaily() - { - if (!$this->byHour && !$this->byDay) { - $this->currentDate = $this->currentDate->modify('+'.$this->interval.' days'); + protected function nextDaily() { + if (!$this->byHour && !$this->byDay) { + $this->currentDate = $this->currentDate->modify('+' . $this->interval . ' days'); return; } @@ -336,14 +352,16 @@ class RRuleIterator implements Iterator do { if ($this->byHour) { - if ('23' == $this->currentDate->format('G')) { + if ($this->currentDate->format('G') == '23') { // to obey the interval rule - $this->currentDate = $this->currentDate->modify('+'.$this->interval - 1 .' days'); + $this->currentDate = $this->currentDate->modify('+' . $this->interval - 1 . ' days'); } $this->currentDate = $this->currentDate->modify('+1 hours'); + } else { - $this->currentDate = $this->currentDate->modify('+'.$this->interval.' days'); + $this->currentDate = $this->currentDate->modify('+' . $this->interval . ' days'); + } // Current month of the year @@ -354,21 +372,24 @@ class RRuleIterator implements Iterator // Current hour of the day $currentHour = $this->currentDate->format('G'); + } while ( ($this->byDay && !in_array($currentDay, $recurrenceDays)) || ($this->byHour && !in_array($currentHour, $recurrenceHours)) || ($this->byMonth && !in_array($currentMonth, $recurrenceMonths)) ); + } /** * Does the processing for advancing the iterator for weekly frequency. + * + * @return void */ - protected function nextWeekly() - { - if (!$this->byHour && !$this->byDay) { - $this->currentDate = $this->currentDate->modify('+'.$this->interval.' weeks'); + protected function nextWeekly() { + if (!$this->byHour && !$this->byDay) { + $this->currentDate = $this->currentDate->modify('+' . $this->interval . ' weeks'); return; } @@ -384,6 +405,7 @@ class RRuleIterator implements Iterator $firstDay = $this->dayMap[$this->weekStart]; do { + if ($this->byHour) { $this->currentDate = $this->currentDate->modify('+1 hours'); } else { @@ -391,19 +413,19 @@ class RRuleIterator implements Iterator } // Current day of the week - $currentDay = (int) $this->currentDate->format('w'); + $currentDay = (int)$this->currentDate->format('w'); // Current hour of the day - $currentHour = (int) $this->currentDate->format('G'); + $currentHour = (int)$this->currentDate->format('G'); // We need to roll over to the next week - if ($currentDay === $firstDay && (!$this->byHour || '0' == $currentHour)) { - $this->currentDate = $this->currentDate->modify('+'.$this->interval - 1 .' weeks'); + if ($currentDay === $firstDay && (!$this->byHour || $currentHour == '0')) { + $this->currentDate = $this->currentDate->modify('+' . $this->interval - 1 . ' weeks'); // We need to go to the first day of this week, but only if we // are not already on this first day of this week. if ($this->currentDate->format('w') != $firstDay) { - $this->currentDate = $this->currentDate->modify('last '.$this->dayNames[$this->dayMap[$this->weekStart]]); + $this->currentDate = $this->currentDate->modify('last ' . $this->dayNames[$this->dayMap[$this->weekStart]]); } } @@ -413,38 +435,43 @@ class RRuleIterator implements Iterator /** * Does the processing for advancing the iterator for monthly frequency. + * + * @return void */ - protected function nextMonthly() - { + protected function nextMonthly() { + $currentDayOfMonth = $this->currentDate->format('j'); if (!$this->byMonthDay && !$this->byDay) { + // If the current day is higher than the 28th, rollover can // occur to the next month. We Must skip these invalid // entries. if ($currentDayOfMonth < 29) { - $this->currentDate = $this->currentDate->modify('+'.$this->interval.' months'); + $this->currentDate = $this->currentDate->modify('+' . $this->interval . ' months'); } else { $increase = 0; do { - ++$increase; + $increase++; $tempDate = clone $this->currentDate; - $tempDate = $tempDate->modify('+ '.($this->interval * $increase).' months'); + $tempDate = $tempDate->modify('+ ' . ($this->interval * $increase) . ' months'); } while ($tempDate->format('j') != $currentDayOfMonth); $this->currentDate = $tempDate; } - return; } while (true) { + $occurrences = $this->getMonthlyOccurrences(); foreach ($occurrences as $occurrence) { + // The first occurrence thats higher than the current // day of the month wins. if ($occurrence > $currentDayOfMonth) { break 2; } + } // If we made it all the way here, it means there were no @@ -456,36 +483,42 @@ class RRuleIterator implements Iterator // $this->currentDate->modify('first day of this month'); $this->currentDate = new DateTimeImmutable($this->currentDate->format('Y-m-1 H:i:s'), $this->currentDate->getTimezone()); // end of workaround - $this->currentDate = $this->currentDate->modify('+ '.$this->interval.' months'); + $this->currentDate = $this->currentDate->modify('+ ' . $this->interval . ' months'); // This goes to 0 because we need to start counting at the // beginning. $currentDayOfMonth = 0; + } $this->currentDate = $this->currentDate->setDate( - (int) $this->currentDate->format('Y'), - (int) $this->currentDate->format('n'), - (int) $occurrence + (int)$this->currentDate->format('Y'), + (int)$this->currentDate->format('n'), + (int)$occurrence ); + } /** * Does the processing for advancing the iterator for yearly frequency. + * + * @return void */ - protected function nextYearly() - { + protected function nextYearly() { + $currentMonth = $this->currentDate->format('n'); $currentYear = $this->currentDate->format('Y'); $currentDayOfMonth = $this->currentDate->format('j'); // No sub-rules, so we just advance by year if (empty($this->byMonth)) { + // Unless it was a leap day! - if (2 == $currentMonth && 29 == $currentDayOfMonth) { + if ($currentMonth == 2 && $currentDayOfMonth == 29) { + $counter = 0; do { - ++$counter; + $counter++; // Here we increase the year count by the interval, until // we hit a date that's also in a leap year. // @@ -495,15 +528,16 @@ class RRuleIterator implements Iterator // 400. (1800, 1900, 2100). So we just rely on the datetime // functions instead. $nextDate = clone $this->currentDate; - $nextDate = $nextDate->modify('+ '.($this->interval * $counter).' years'); - } while (2 != $nextDate->format('n')); + $nextDate = $nextDate->modify('+ ' . ($this->interval * $counter) . ' years'); + } while ($nextDate->format('n') != 2); $this->currentDate = $nextDate; return; + } - if (null !== $this->byWeekNo) { // byWeekNo is an array with values from -53 to -1, or 1 to 53 + if ($this->byWeekNo !== null) { // byWeekNo is an array with values from -53 to -1, or 1 to 53 $dayOffsets = []; if ($this->byDay) { foreach ($this->byDay as $byDay) { @@ -532,7 +566,6 @@ class RRuleIterator implements Iterator if (count($checkDates) > 0) { $this->currentDate = min($checkDates); - return; } @@ -541,14 +574,14 @@ class RRuleIterator implements Iterator } } - if (null !== $this->byYearDay) { // byYearDay is an array with values from -366 to -1, or 1 to 366 + if ($this->byYearDay !== null) { // byYearDay is an array with values from -366 to -1, or 1 to 366 $dayOffsets = []; if ($this->byDay) { foreach ($this->byDay as $byDay) { $dayOffsets[] = $this->dayMap[$byDay]; } } else { // default is Monday-Sunday - $dayOffsets = [1, 2, 3, 4, 5, 6, 7]; + $dayOffsets = [1,2,3,4,5,6,7]; } $currentYear = $this->currentDate->format('Y'); @@ -561,9 +594,9 @@ class RRuleIterator implements Iterator $date = clone $this->currentDate; $date = $date->setDate($currentYear, 1, 1); if ($byYearDay > 0) { - $date = $date->add(new \DateInterval('P'.$byYearDay.'D')); + $date = $date->add(new \DateInterval('P' . $byYearDay . 'D')); } else { - $date = $date->sub(new \DateInterval('P'.abs($byYearDay).'D')); + $date = $date->sub(new \DateInterval('P' . abs($byYearDay) . 'D')); } if ($date > $this->currentDate && in_array($date->format('N'), $dayOffsets)) { @@ -573,7 +606,6 @@ class RRuleIterator implements Iterator if (count($checkDates) > 0) { $this->currentDate = min($checkDates); - return; } @@ -583,9 +615,9 @@ class RRuleIterator implements Iterator } // The easiest form - $this->currentDate = $this->currentDate->modify('+'.$this->interval.' years'); - + $this->currentDate = $this->currentDate->modify('+' . $this->interval . ' years'); return; + } $currentMonth = $this->currentDate->format('n'); @@ -597,10 +629,13 @@ class RRuleIterator implements Iterator // If we got a byDay or getMonthDay filter, we must first expand // further. if ($this->byDay || $this->byMonthDay) { + while (true) { + $occurrences = $this->getMonthlyOccurrences(); foreach ($occurrences as $occurrence) { + // The first occurrence that's higher than the current // day of the month wins. // If we advanced to the next month or year, the first @@ -608,6 +643,7 @@ class RRuleIterator implements Iterator if ($occurrence > $currentDayOfMonth || $advancedToNewMonth) { break 2; } + } // If we made it here, it means we need to advance to @@ -615,7 +651,8 @@ class RRuleIterator implements Iterator $currentDayOfMonth = 1; $advancedToNewMonth = true; do { - ++$currentMonth; + + $currentMonth++; if ($currentMonth > 12) { $currentYear += $this->interval; $currentMonth = 1; @@ -623,38 +660,43 @@ class RRuleIterator implements Iterator } while (!in_array($currentMonth, $this->byMonth)); $this->currentDate = $this->currentDate->setDate( - (int) $currentYear, - (int) $currentMonth, - (int) $currentDayOfMonth + (int)$currentYear, + (int)$currentMonth, + (int)$currentDayOfMonth ); + } // If we made it here, it means we got a valid occurrence $this->currentDate = $this->currentDate->setDate( - (int) $currentYear, - (int) $currentMonth, - (int) $occurrence + (int)$currentYear, + (int)$currentMonth, + (int)$occurrence ); - return; + } else { + // These are the 'byMonth' rules, if there are no byDay or // byMonthDay sub-rules. do { - ++$currentMonth; + + $currentMonth++; if ($currentMonth > 12) { $currentYear += $this->interval; $currentMonth = 1; } } while (!in_array($currentMonth, $this->byMonth)); $this->currentDate = $this->currentDate->setDate( - (int) $currentYear, - (int) $currentMonth, - (int) $currentDayOfMonth + (int)$currentYear, + (int)$currentMonth, + (int)$currentDayOfMonth ); return; + } + } /* }}} */ @@ -664,28 +706,32 @@ class RRuleIterator implements Iterator * class with all the values. * * @param string|array $rrule + * + * @return void */ - protected function parseRRule($rrule) - { + protected function parseRRule($rrule) { + if (is_string($rrule)) { $rrule = Property\ICalendar\Recur::stringToArray($rrule); } foreach ($rrule as $key => $value) { + $key = strtoupper($key); switch ($key) { - case 'FREQ': + + case 'FREQ' : $value = strtolower($value); if (!in_array( $value, ['secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'] )) { - throw new InvalidDataException('Unknown value for FREQ='.strtoupper($value)); + throw new InvalidDataException('Unknown value for FREQ=' . strtoupper($value)); } $this->frequency = $value; break; - case 'UNTIL': + case 'UNTIL' : $this->until = DateTimeParser::parse($value, $this->startDate->getTimezone()); // In some cases events are generated with an UNTIL= @@ -701,82 +747,86 @@ class RRuleIterator implements Iterator } break; - case 'INTERVAL': + case 'INTERVAL' : + // No break - case 'COUNT': - $val = (int) $value; + case 'COUNT' : + $val = (int)$value; if ($val < 1) { - throw new InvalidDataException(strtoupper($key).' in RRULE must be a positive integer!'); + throw new InvalidDataException(strtoupper($key) . ' in RRULE must be a positive integer!'); } $key = strtolower($key); $this->$key = $val; break; - case 'BYSECOND': - $this->bySecond = (array) $value; + case 'BYSECOND' : + $this->bySecond = (array)$value; break; - case 'BYMINUTE': - $this->byMinute = (array) $value; + case 'BYMINUTE' : + $this->byMinute = (array)$value; break; - case 'BYHOUR': - $this->byHour = (array) $value; + case 'BYHOUR' : + $this->byHour = (array)$value; break; - case 'BYDAY': - $value = (array) $value; + case 'BYDAY' : + $value = (array)$value; foreach ($value as $part) { if (!preg_match('#^ (-|\+)? ([1-5])? (MO|TU|WE|TH|FR|SA|SU) $# xi', $part)) { - throw new InvalidDataException('Invalid part in BYDAY clause: '.$part); + throw new InvalidDataException('Invalid part in BYDAY clause: ' . $part); } } $this->byDay = $value; break; - case 'BYMONTHDAY': - $this->byMonthDay = (array) $value; + case 'BYMONTHDAY' : + $this->byMonthDay = (array)$value; break; - case 'BYYEARDAY': - $this->byYearDay = (array) $value; + case 'BYYEARDAY' : + $this->byYearDay = (array)$value; foreach ($this->byYearDay as $byYearDay) { - if (!is_numeric($byYearDay) || (int) $byYearDay < -366 || 0 == (int) $byYearDay || (int) $byYearDay > 366) { + if (!is_numeric($byYearDay) || (int)$byYearDay < -366 || (int)$byYearDay == 0 || (int)$byYearDay > 366) { throw new InvalidDataException('BYYEARDAY in RRULE must have value(s) from 1 to 366, or -366 to -1!'); } } break; - case 'BYWEEKNO': - $this->byWeekNo = (array) $value; + case 'BYWEEKNO' : + $this->byWeekNo = (array)$value; foreach ($this->byWeekNo as $byWeekNo) { - if (!is_numeric($byWeekNo) || (int) $byWeekNo < -53 || 0 == (int) $byWeekNo || (int) $byWeekNo > 53) { + if (!is_numeric($byWeekNo) || (int)$byWeekNo < -53 || (int)$byWeekNo == 0 || (int)$byWeekNo > 53) { throw new InvalidDataException('BYWEEKNO in RRULE must have value(s) from 1 to 53, or -53 to -1!'); } } break; - case 'BYMONTH': - $this->byMonth = (array) $value; + case 'BYMONTH' : + $this->byMonth = (array)$value; foreach ($this->byMonth as $byMonth) { - if (!is_numeric($byMonth) || (int) $byMonth < 1 || (int) $byMonth > 12) { + if (!is_numeric($byMonth) || (int)$byMonth < 1 || (int)$byMonth > 12) { throw new InvalidDataException('BYMONTH in RRULE must have value(s) betweeen 1 and 12!'); } } break; - case 'BYSETPOS': - $this->bySetPos = (array) $value; + case 'BYSETPOS' : + $this->bySetPos = (array)$value; break; - case 'WKST': + case 'WKST' : $this->weekStart = strtoupper($value); break; default: - throw new InvalidDataException('Not supported: '.strtoupper($key)); + throw new InvalidDataException('Not supported: ' . strtoupper($key)); + } + } + } /** @@ -802,75 +852,77 @@ class RRuleIterator implements Iterator * * @return array */ - protected function getMonthlyOccurrences() - { + protected function getMonthlyOccurrences() { + $startDate = clone $this->currentDate; $byDayResults = []; // Our strategy is to simply go through the byDays, advance the date to // that point and add it to the results. - if ($this->byDay) { - foreach ($this->byDay as $day) { - $dayName = $this->dayNames[$this->dayMap[substr($day, -2)]]; - - // Dayname will be something like 'wednesday'. Now we need to find - // all wednesdays in this month. - $dayHits = []; - - // workaround for missing 'first day of the month' support in hhvm - $checkDate = new \DateTime($startDate->format('Y-m-1')); - // workaround modify always advancing the date even if the current day is a $dayName in hhvm - if ($checkDate->format('l') !== $dayName) { - $checkDate = $checkDate->modify($dayName); - } + if ($this->byDay) foreach ($this->byDay as $day) { - do { - $dayHits[] = $checkDate->format('j'); - $checkDate = $checkDate->modify('next '.$dayName); - } while ($checkDate->format('n') === $startDate->format('n')); - - // So now we have 'all wednesdays' for month. It is however - // possible that the user only really wanted the 1st, 2nd or last - // wednesday. - if (strlen($day) > 2) { - $offset = (int) substr($day, 0, -2); - - if ($offset > 0) { - // It is possible that the day does not exist, such as a - // 5th or 6th wednesday of the month. - if (isset($dayHits[$offset - 1])) { - $byDayResults[] = $dayHits[$offset - 1]; - } - } else { - // if it was negative we count from the end of the array - // might not exist, fx. -5th tuesday - if (isset($dayHits[count($dayHits) + $offset])) { - $byDayResults[] = $dayHits[count($dayHits) + $offset]; - } + $dayName = $this->dayNames[$this->dayMap[substr($day, -2)]]; + + + // Dayname will be something like 'wednesday'. Now we need to find + // all wednesdays in this month. + $dayHits = []; + + // workaround for missing 'first day of the month' support in hhvm + $checkDate = new \DateTime($startDate->format('Y-m-1')); + // workaround modify always advancing the date even if the current day is a $dayName in hhvm + if ($checkDate->format('l') !== $dayName) { + $checkDate = $checkDate->modify($dayName); + } + + do { + $dayHits[] = $checkDate->format('j'); + $checkDate = $checkDate->modify('next ' . $dayName); + } while ($checkDate->format('n') === $startDate->format('n')); + + // So now we have 'all wednesdays' for month. It is however + // possible that the user only really wanted the 1st, 2nd or last + // wednesday. + if (strlen($day) > 2) { + $offset = (int)substr($day, 0, -2); + + if ($offset > 0) { + // It is possible that the day does not exist, such as a + // 5th or 6th wednesday of the month. + if (isset($dayHits[$offset - 1])) { + $byDayResults[] = $dayHits[$offset - 1]; } } else { - // There was no counter (first, second, last wednesdays), so we - // just need to add the all to the list). - $byDayResults = array_merge($byDayResults, $dayHits); + + // if it was negative we count from the end of the array + // might not exist, fx. -5th tuesday + if (isset($dayHits[count($dayHits) + $offset])) { + $byDayResults[] = $dayHits[count($dayHits) + $offset]; + } } + } else { + // There was no counter (first, second, last wednesdays), so we + // just need to add the all to the list). + $byDayResults = array_merge($byDayResults, $dayHits); + } + } $byMonthDayResults = []; - if ($this->byMonthDay) { - foreach ($this->byMonthDay as $monthDay) { - // Removing values that are out of range for this month - if ($monthDay > $startDate->format('t') || + if ($this->byMonthDay) foreach ($this->byMonthDay as $monthDay) { + + // Removing values that are out of range for this month + if ($monthDay > $startDate->format('t') || $monthDay < 0 - $startDate->format('t')) { continue; - } - if ($monthDay > 0) { - $byMonthDayResults[] = $monthDay; - } else { - // Negative values - $byMonthDayResults[] = $startDate->format('t') + 1 + $monthDay; - } + } + if ($monthDay > 0) { + $byMonthDayResults[] = $monthDay; + } else { + // Negative values + $byMonthDayResults[] = $startDate->format('t') + 1 + $monthDay; } } @@ -895,6 +947,7 @@ class RRuleIterator implements Iterator $filteredResult = []; foreach ($this->bySetPos as $setPos) { + if ($setPos < 0) { $setPos = count($result) + ($setPos + 1); } @@ -904,8 +957,8 @@ class RRuleIterator implements Iterator } sort($filteredResult, SORT_NUMERIC); - return $filteredResult; + } /** @@ -923,8 +976,8 @@ class RRuleIterator implements Iterator 'SA' => 6, ]; - protected function getHours() - { + protected function getHours() { + $recurrenceHours = []; foreach ($this->byHour as $byHour) { $recurrenceHours[] = $byHour; @@ -933,21 +986,23 @@ class RRuleIterator implements Iterator return $recurrenceHours; } - protected function getDays() - { + protected function getDays() { + $recurrenceDays = []; foreach ($this->byDay as $byDay) { + // The day may be preceeded with a positive (+n) or // negative (-n) integer. However, this does not make // sense in 'weekly' so we ignore it here. $recurrenceDays[] = $this->dayMap[substr($byDay, -2)]; + } return $recurrenceDays; } - protected function getMonths() - { + protected function getMonths() { + $recurrenceMonths = []; foreach ($this->byMonth as $byMonth) { $recurrenceMonths[] = $byMonth; -- cgit v1.2.3