Skip to content

Commit

Permalink
Merge pull request #656 from kroky/bugfix/bymonth-rrule
Browse files Browse the repository at this point in the history
Yearly rrule compliance by the iterator
  • Loading branch information
phil-davis authored May 17, 2024
2 parents a865996 + 72a1fe9 commit 254f85d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Recur/RRuleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,11 @@ protected function nextYearly(): void
// If we advanced to the next month or year, the first
// occurrence is always correct.
if ($occurrence > $currentDayOfMonth || $advancedToNewMonth) {
break 2;
// only consider byMonth matches,
// otherwise, we don't follow RRule correctly
if (in_array($currentMonth, $this->byMonth)) {
break 2;
}
}
}

Expand Down
46 changes: 46 additions & 0 deletions tests/VObject/Recur/RRuleIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,52 @@ public function testYearlyBySetPosLoop(): void
);
}

/**
* This caused an incorrect date to be returned by the rule iterator when
* start date was not on the rrule list.
*
* @dataProvider yearlyStartDateNotOnRRuleListProvider
*/
public function testYearlyStartDateNotOnRRuleList(string $rule, string $start, array $expected): void
{
$this->parse($rule, $start, $expected);
}

public function yearlyStartDateNotOnRRuleListProvider(): array
{
return [
[
'FREQ=YEARLY;BYMONTH=6;BYDAY=-1FR;UNTIL=20250901T000000Z',
'2023-09-01 12:00:00',
[
'2023-09-01 12:00:00',
'2024-06-28 12:00:00',
'2025-06-27 12:00:00',
],
],
[
'FREQ=YEARLY;BYMONTH=6;BYDAY=-1FR;UNTIL=20250901T000000Z',
'2023-06-01 12:00:00',
[
'2023-06-01 12:00:00',
'2023-06-30 12:00:00',
'2024-06-28 12:00:00',
'2025-06-27 12:00:00',
],
],
[
'FREQ=YEARLY;BYMONTH=6;BYDAY=-1FR;UNTIL=20250901T000000Z',
'2023-05-01 12:00:00',
[
'2023-05-01 12:00:00',
'2023-06-30 12:00:00',
'2024-06-28 12:00:00',
'2025-06-27 12:00:00',
],
],
];
}

/**
* Something, somewhere produced an ics with an interval set to 0. Because
* this means we increase the current day (or week, month) by 0, this also
Expand Down

0 comments on commit 254f85d

Please sign in to comment.