Skip to content

Commit

Permalink
Merge pull request #532 from jaircuevajunior/fix-montly-not-respectin…
Browse files Browse the repository at this point in the history
…g-until

Make use of until parameter in nextMonthly function
  • Loading branch information
phil-davis authored Feb 12, 2021
2 parents 3168acd + 1bbae65 commit 38bc2d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Recur/RRuleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,13 @@ protected function nextMonthly()
// beginning.
$currentDayOfMonth = 0;

// For some reason the "until" parameter was not being used here,
// that's why the workaround of the 10000 year bug was needed at all
// let's stop it before the "until" parameter date
if ($this->until && $this->currentDate->getTimestamp() >= $this->until->getTimestamp()) {
return;
}

// 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) {
Expand Down Expand Up @@ -876,7 +883,7 @@ protected function getMonthlyOccurrences()
foreach ($this->byMonthDay as $monthDay) {
// Removing values that are out of range for this month
if ($monthDay > $startDate->format('t') ||
$monthDay < 0 - $startDate->format('t')) {
$monthDay < 0 - $startDate->format('t')) {
continue;
}
if ($monthDay > 0) {
Expand Down
27 changes: 27 additions & 0 deletions tests/VObject/Recur/RRuleIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@ public function testMonthlyByDay()
);
}

public function testMonthlyByDayUntil()
{
$this->parse(
'FREQ=MONTHLY;INTERVAL=1;BYDAY=WE;WKST=WE;UNTIL=20210317T000000Z',
'2021-02-10 00:00:00',
[
'2021-02-10 00:00:00',
'2021-02-17 00:00:00',
'2021-02-24 00:00:00',
'2021-03-03 00:00:00',
'2021-03-10 00:00:00',
'2021-03-17 00:00:00',
]
);
}

public function testMonthlyByDayUntilWithImpossibleNextOccurrence()
{
$this->parse(
'FREQ=MONTHLY;INTERVAL=1;BYDAY=2WE;BYMONTHDAY=2;WKST=WE;UNTIL=20210317T000000Z',
'2021-02-10 00:00:00',
[
'2021-02-10 00:00:00',
]
);
}

public function testMonthlyByDayByMonthDay()
{
$this->parse(
Expand Down

0 comments on commit 38bc2d2

Please sign in to comment.