Skip to content

Commit

Permalink
make test pass from both sides
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Szu committed Dec 29, 2023
1 parent 8639abe commit 267b237
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
13 changes: 12 additions & 1 deletion lib/Recur/RRuleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ class RRuleIterator implements \Iterator
*/
public const dateUpperLimit = 253402300799;

private bool $yearlySkipUpperLimit;

/**
* Creates the Iterator.
*
* @param string|array $rrule
*
* @throws InvalidDataException
*/
public function __construct($rrule, \DateTimeInterface $start)
public function __construct($rrule, \DateTimeInterface $start, bool $yearlySkipUpperLimit = true)
{
$this->startDate = $start;
$this->parseRRule($rrule);
$this->currentDate = clone $this->startDate;
$this->yearlySkipUpperLimit = $yearlySkipUpperLimit;
}

/* Implementation of the Iterator interface {{{ */
Expand Down Expand Up @@ -823,6 +826,14 @@ protected function nextYearly($amount = 1): void
(int) $currentMonth,
(int) $currentDayOfMonth
);

// 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->yearlySkipUpperLimit && ($this->currentDate->getTimestamp() > self::dateUpperLimit)) {
$this->currentDate = null;

return;
}
}

// If we made it here, it means we got a valid occurrence
Expand Down
3 changes: 3 additions & 0 deletions tests/VObject/Recur/FastForwardToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public function testFastForwardToEndUntilMonthly31thDay()
$this->assertEquals($expected, $rrule->current()->getTimestamp());
}

/**
* @medium
*/
public function testFastForwardToEndCountMonthlyAdvanced()
{
$startDate = new \DateTime('1970-01-31 00:00:00', new \DateTimeZone('America/New_York'));
Expand Down
14 changes: 11 additions & 3 deletions tests/VObject/Recur/RRuleIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,14 @@ public function testYearlyBySetPosLoop(): void
'FREQ=YEARLY;BYMONTH=5;BYSETPOS=3;BYMONTHDAY=3',
'2022-03-03 15:45:00',
[],
'yearly', null, 1, null, '2022-05-01'
'yearly',
null,
1,
null,
'2022-05-01',
'UTC',
false,
false,
);
}

Expand Down Expand Up @@ -1245,10 +1252,11 @@ public function parse(
$expectedUntil = null,
string $fastForward = null,
string $tz = 'UTC',
bool $runTillTheEnd = false
bool $runTillTheEnd = false,
bool $yearlySkipUpperLimit = true
): void {
$dt = new \DateTime($start, new \DateTimeZone($tz));
$parser = new RRuleIterator($rule, $dt);
$parser = new RRuleIterator($rule, $dt, $yearlySkipUpperLimit);

$this->assertEquals($expectedFreq, $parser->getFrequency());
$this->assertEquals($expectedCount, $parser->getCount());
Expand Down

0 comments on commit 267b237

Please sign in to comment.