Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 566 - Endless loop problem in RRuleIterator::nextDaily #567

Merged
merged 5 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/Recur/RRuleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
*/
class RRuleIterator implements Iterator
{
/**
* Constant denoting the upper limit on how long into the future
* we want to iterate. The value is a unix timestamp and currently
* corresponds to the datetime 9999-12-31 11:59:59 UTC.
*/
const dateUpperLimit = 253402300799;

/**
* Creates the Iterator.
*
Expand Down Expand Up @@ -366,6 +373,12 @@ protected function nextDaily()

// Current hour of the day
$currentHour = $this->currentDate->format('G');

if ($this->currentDate->getTimestamp() > self::dateUpperLimit) {
$this->currentDate = null;

return;
}
} while (
($this->byDay && !in_array($currentDay, $recurrenceDays)) ||
($this->byHour && !in_array($currentHour, $recurrenceHours)) ||
Expand Down Expand Up @@ -486,7 +499,7 @@ protected function nextMonthly()

// To prevent running this forever (better: until we hit the max date of DateTimeImmutable) we simply
// stop at 9999-12-31. Looks like the year 10000 problem is not solved in php ....
if ($this->currentDate->getTimestamp() > 253402300799) {
if ($this->currentDate->getTimestamp() > self::dateUpperLimit) {
$this->currentDate = null;

return;
Expand Down Expand Up @@ -661,7 +674,7 @@ protected function nextYearly()

// To prevent running this forever (better: until we hit the max date of DateTimeImmutable) we simply
// stop at 9999-12-31. Looks like the year 10000 problem is not solved in php ....
if ($this->currentDate->getTimestamp() > 253402300799) {
if ($this->currentDate->getTimestamp() > self::dateUpperLimit) {
$this->currentDate = null;

return;
Expand Down
25 changes: 25 additions & 0 deletions tests/VObject/Recur/RRuleIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ public function testDailyByMonth()
);
}

/**
* This test can take some seconds to complete.
* The "large" annotation means phpunit will let it run for
* up to 60 seconds by default.
*
* @large
*/
public function testDailyBySetPosLoop()
{
$this->parse(
'FREQ=DAILY;INTERVAL=7;BYDAY=MO',
'2022-03-15',
[
],
'2022-05-01'
);
}

public function testWeekly()
{
$this->parse(
Expand Down Expand Up @@ -825,6 +843,13 @@ public function testYearlyByMonthLoop()
);
}

/**
* This test can take some seconds to complete.
* The "large" annotation means phpunit will let it run for
* up to 60 seconds by default.
*
* @large
*/
public function testYearlyBySetPosLoop()
{
$this->parse(
Expand Down