Skip to content

Commit

Permalink
Get rid of named parameters, get rid multi-type parameters, and updat…
Browse files Browse the repository at this point in the history
…e timezone guesser test
  • Loading branch information
cyrilvanschreven-proton committed Apr 22, 2024
1 parent 90e3154 commit d9f246d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
48 changes: 24 additions & 24 deletions lib/Recur/RRuleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand All @@ -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]]);
}
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
16 changes: 9 additions & 7 deletions tests/VObject/Recur/RRuleIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/VObject/TimeZoneUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public function testCustomizedTimeZone(): void
$ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//ical.marudot.com//iCal Event Maker
PRODID:-//ical.marudot.com//iCal Event Maker
X-WR-CALNAME:Victorian public holiday dates
NAME:Victorian public holiday dates
CALSCALE:GREGORIAN
Expand Down Expand Up @@ -675,7 +675,7 @@ public function testCustomizedTimeZoneWithoutDaylight(): void
{
$ics = $this->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));
}
Expand Down

0 comments on commit d9f246d

Please sign in to comment.