From d9f246d62609d6cb4b9fba043e00962bf55538e0 Mon Sep 17 00:00:00 2001 From: Cyril van Schreven Date: Mon, 22 Apr 2024 11:09:33 +0200 Subject: [PATCH] Get rid of named parameters, get rid multi-type parameters, and update timezone guesser test --- lib/Recur/RRuleIterator.php | 48 +++++++++++------------ tests/VObject/Recur/RRuleIteratorTest.php | 16 ++++---- tests/VObject/TimeZoneUtilTest.php | 4 +- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php index bd1009298..34f2cb90c 100644 --- a/lib/Recur/RRuleIterator.php +++ b/lib/Recur/RRuleIterator.php @@ -440,7 +440,7 @@ private function jumpForward(\DateTimeInterface $dt): void */ protected function nextHourly($amount = 1): void { - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+'.$amount * $this->interval.' hours'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.$amount * $this->interval.' hours'); } /** @@ -449,7 +449,7 @@ protected function nextHourly($amount = 1): void protected function nextDaily($amount = 1): void { if (!$this->byHour && !$this->byDay) { - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+'.$amount * $this->interval.' days'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.$amount * $this->interval.' days'); return; } @@ -473,13 +473,13 @@ protected function nextDaily($amount = 1): void if ($this->byHour) { if ('23' == $this->currentDate->format('G')) { // to obey the interval rule - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+'.(($amount * $this->interval) - 1).' days'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.(($amount * $this->interval) - 1).' days'); $amount = 1; } - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+1 hours'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+1 hours'); } else { - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+'.($amount * $this->interval).' days'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.($amount * $this->interval).' days'); $amount = 1; } @@ -510,7 +510,7 @@ protected function nextDaily($amount = 1): void protected function nextWeekly($amount = 1): void { if (!$this->byHour && !$this->byDay) { - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+'.($amount * $this->interval).' weeks'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.($amount * $this->interval).' weeks'); return; } @@ -530,9 +530,9 @@ protected function nextWeekly($amount = 1): void do { if ($this->byHour) { - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+1 hours'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+1 hours'); } else { - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+1 days'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+1 days'); } // Current day of the week @@ -543,12 +543,12 @@ protected function nextWeekly($amount = 1): void // We need to roll over to the next week if ($currentDay === $firstDay && (!$this->byHour || '0' == $currentHour)) { - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+'.(($amount * $this->interval) - 1).' weeks'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.(($amount * $this->interval) - 1).' weeks'); $amount = 1; // 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->getNextIterationDateTime($this->currentDate, modify: 'last '.$this->dayNames[$this->dayMap[$this->weekStart]]); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, 'last '.$this->dayNames[$this->dayMap[$this->weekStart]]); } } @@ -572,13 +572,13 @@ protected function nextMonthly($amount = 1): void // occur to the next month. We Must skip these invalid // entries. if ($currentDayOfMonth < 29) { - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+'.($amount * $this->interval).' months'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.($amount * $this->interval).' months'); } else { $increase = $amount - 1; do { ++$increase; $tempDate = clone $this->currentDate; - $tempDate = $this->getNextIterationDateTime($tempDate, modify: '+ '.($this->interval * $increase).' months'); + $tempDate = $this->getNextIterationDateTime($tempDate, '+ '.($this->interval * $increase).' months'); } while ($tempDate->format('j') != $currentDayOfMonth); $this->currentDate = $tempDate; } @@ -623,7 +623,7 @@ protected function nextMonthly($amount = 1): void 1 ); // end of workaround - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+ '.($amount * $this->interval).' months'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+ '.($amount * $this->interval).' months'); $amount = 1; // This goes to 0 because we need to start counting at the @@ -684,7 +684,7 @@ protected function nextYearly($amount = 1): void // 400. (1800, 1900, 2100). So we just rely on the datetime // functions instead. $nextDate = clone $this->currentDate; - $nextDate = $this->getNextIterationDateTime($nextDate, modify: '+ '.($this->interval * $counter).' years'); + $nextDate = $this->getNextIterationDateTime($nextDate, '+ '.($this->interval * $counter).' years'); } while (2 != $nextDate->format('n')); $this->currentDate = $nextDate; @@ -775,7 +775,7 @@ protected function nextYearly($amount = 1): void } // The easiest form - $this->currentDate = $this->getNextIterationDateTime($this->currentDate, modify: '+'.($amount * $this->interval).' years'); + $this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.($amount * $this->interval).' years'); return; } @@ -1239,7 +1239,7 @@ protected function getMonths(): array return $recurrenceMonths; } - private function getNextIterationDateTime(\DateTimeImmutable|\DateTime $dateTime, string $modify): \DateTimeImmutable|\DateTime + private function getNextIterationDateTime(\DateTimeInterface $dateTime, string $modify): \DateTimeInterface { $startTs = $dateTime->getTimestamp(); $initialDateTime = clone $dateTime; @@ -1257,8 +1257,8 @@ private function getNextIterationDateTime(\DateTimeImmutable|\DateTime $dateTime } private function detectAndSaveDstOffset( - \DateTimeImmutable|\DateTime $initialDateTime, - \DateTimeImmutable|\DateTime $modifiedDateTime, + \DateTimeInterface $initialDateTime, + \DateTimeInterface $modifiedDateTime, string $modify, ) { $dstTransitionLeap = $this->getDstTransitionLeap($initialDateTime, $modifiedDateTime, $modify); @@ -1269,8 +1269,8 @@ private function detectAndSaveDstOffset( } private function getDstTransitionLeap( - \DateTimeImmutable|\DateTime $initialDateTime, - \DateTimeImmutable|\DateTime $modifiedDateTime, + \DateTimeInterface $initialDateTime, + \DateTimeInterface $modifiedDateTime, string $modify, ): ?int { $modifiedDateInterval = $this->substractDates($modifiedDateTime, $initialDateTime); @@ -1289,13 +1289,13 @@ private function isDstTransitionLeap(\DateInterval $leap): bool return $leap->y === 0 && $leap->m === 0 && $leap->d === 0 && $leap->h > 0 && $leap->i === 0 && $leap->s === 0; } - private function revertPastOffset(\DateTimeImmutable|\DateTime $dateTime): \DateTimeImmutable|\DateTime + private function revertPastOffset(\DateTimeInterface $dateTime): \DateTimeInterface { if (!is_numeric($this->counter)) { return $dateTime; } - $previousIterationLeapOffset = $this->leapOffset[$this->counter - 1] ?? null; + $previousIterationLeapOffset = $this->leapOffset[(int) $this->counter - 1] ?? null; if (!is_int($previousIterationLeapOffset)) { return $dateTime; @@ -1323,8 +1323,8 @@ private function substractIntervals(\DateInterval $dateIntervalOne, \DateInterva } private function substractDates( - \DateTimeImmutable|\DateTime $dateIntervalOne, - \DateTimeImmutable|\DateTime $dateIntervalTwo, + \DateTimeInterface $dateIntervalOne, + \DateTimeInterface $dateIntervalTwo, ): \DateInterval { $yearsDiff = $dateIntervalOne->format('y') - $dateIntervalTwo->format('y'); $monthsDiff = $dateIntervalOne->format('m') - $dateIntervalTwo->format('m'); diff --git a/tests/VObject/Recur/RRuleIteratorTest.php b/tests/VObject/Recur/RRuleIteratorTest.php index bfe3d36c5..0f7630a54 100644 --- a/tests/VObject/Recur/RRuleIteratorTest.php +++ b/tests/VObject/Recur/RRuleIteratorTest.php @@ -54,13 +54,15 @@ public function testDaily(): void public function testRecurrenceWithDstTransition(string $start, array $expected): void { $this->parse( - rule:'FREQ=DAILY;INTERVAL=1;COUNT=5', - start: $start, - expected: $expected, - expectedFreq: 'daily', - expectedCount: 5, - expectedInterval: 1, - tz: 'Europe/Zurich', + 'FREQ=DAILY;INTERVAL=1;COUNT=5', + $start, + $expected, + 'daily', + 5, + 1, + null, + null, + 'Europe/Zurich', ); } diff --git a/tests/VObject/TimeZoneUtilTest.php b/tests/VObject/TimeZoneUtilTest.php index 1069b437a..551f04052 100644 --- a/tests/VObject/TimeZoneUtilTest.php +++ b/tests/VObject/TimeZoneUtilTest.php @@ -629,7 +629,7 @@ public function testCustomizedTimeZone(): void $ics = <<getCustomizedICS(); $tz = TimeZoneUtil::getTimeZone('Customized Time Zone', Reader::read($ics)); - self::assertSame('Asia/Brunei', $tz->getName()); + self::assertSame('Antarctica/Casey', $tz->getName()); $start = new \DateTimeImmutable('2022-04-25'); self::assertSame(8 * 60 * 60, $tz->getOffset($start)); }