Skip to content

Commit

Permalink
Do not apply workaround on inner loops
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilvanschreven-proton committed Apr 22, 2024
1 parent 19d0ed4 commit 82ee4e9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 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, '+'.$amount * $this->interval.' hours');
$this->currentDate = $this->currentDate->modify('+'.$amount * $this->interval.' hours');
}

/**
Expand Down Expand Up @@ -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, '+'.(($amount * $this->interval) - 1).' days');
$this->currentDate = $this->currentDate->modify('+'.(($amount * $this->interval) - 1).' days');
$amount = 1;
}

$this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+1 hours');
$this->currentDate = $this->currentDate->modify('+1 hours');
} else {
$this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+'.($amount * $this->interval).' days');
$this->currentDate = $this->currentDate->modify('+'.($amount * $this->interval).' days');
$amount = 1;
}

Expand Down Expand Up @@ -530,9 +530,9 @@ protected function nextWeekly($amount = 1): void

do {
if ($this->byHour) {
$this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+1 hours');
$this->currentDate = $this->currentDate->modify('+1 hours');
} else {
$this->currentDate = $this->getNextIterationDateTime($this->currentDate, '+1 days');
$this->currentDate = $this->currentDate->modify('+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, '+'.(($amount * $this->interval) - 1).' weeks');
$this->currentDate = $this->currentDate->modify('+'.(($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, 'last '.$this->dayNames[$this->dayMap[$this->weekStart]]);
$this->currentDate = $this->currentDate->modify('last '.$this->dayNames[$this->dayMap[$this->weekStart]]);
}
}

Expand Down Expand Up @@ -578,7 +578,7 @@ protected function nextMonthly($amount = 1): void
do {
++$increase;
$tempDate = clone $this->currentDate;
$tempDate = $this->getNextIterationDateTime($tempDate, '+ '.($this->interval * $increase).' months');
$tempDate = $tempDate->modify('+ '.($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, '+ '.($amount * $this->interval).' months');
$this->currentDate = $this->currentDate->modify('+ '.($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, '+ '.($this->interval * $counter).' years');
$nextDate = $nextDate->modify('+ '.($this->interval * $counter).' years');
} while (2 != $nextDate->format('n'));

$this->currentDate = $nextDate;
Expand Down

0 comments on commit 82ee4e9

Please sign in to comment.