Skip to content

Commit 254f85d

Browse files
authored
Merge pull request #656 from kroky/bugfix/bymonth-rrule
Yearly rrule compliance by the iterator
2 parents a865996 + 72a1fe9 commit 254f85d

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

lib/Recur/RRuleIterator.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,11 @@ protected function nextYearly(): void
610610
// If we advanced to the next month or year, the first
611611
// occurrence is always correct.
612612
if ($occurrence > $currentDayOfMonth || $advancedToNewMonth) {
613-
break 2;
613+
// only consider byMonth matches,
614+
// otherwise, we don't follow RRule correctly
615+
if (in_array($currentMonth, $this->byMonth)) {
616+
break 2;
617+
}
614618
}
615619
}
616620

tests/VObject/Recur/RRuleIteratorTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,52 @@ public function testYearlyBySetPosLoop(): void
922922
);
923923
}
924924

925+
/**
926+
* This caused an incorrect date to be returned by the rule iterator when
927+
* start date was not on the rrule list.
928+
*
929+
* @dataProvider yearlyStartDateNotOnRRuleListProvider
930+
*/
931+
public function testYearlyStartDateNotOnRRuleList(string $rule, string $start, array $expected): void
932+
{
933+
$this->parse($rule, $start, $expected);
934+
}
935+
936+
public function yearlyStartDateNotOnRRuleListProvider(): array
937+
{
938+
return [
939+
[
940+
'FREQ=YEARLY;BYMONTH=6;BYDAY=-1FR;UNTIL=20250901T000000Z',
941+
'2023-09-01 12:00:00',
942+
[
943+
'2023-09-01 12:00:00',
944+
'2024-06-28 12:00:00',
945+
'2025-06-27 12:00:00',
946+
],
947+
],
948+
[
949+
'FREQ=YEARLY;BYMONTH=6;BYDAY=-1FR;UNTIL=20250901T000000Z',
950+
'2023-06-01 12:00:00',
951+
[
952+
'2023-06-01 12:00:00',
953+
'2023-06-30 12:00:00',
954+
'2024-06-28 12:00:00',
955+
'2025-06-27 12:00:00',
956+
],
957+
],
958+
[
959+
'FREQ=YEARLY;BYMONTH=6;BYDAY=-1FR;UNTIL=20250901T000000Z',
960+
'2023-05-01 12:00:00',
961+
[
962+
'2023-05-01 12:00:00',
963+
'2023-06-30 12:00:00',
964+
'2024-06-28 12:00:00',
965+
'2025-06-27 12:00:00',
966+
],
967+
],
968+
];
969+
}
970+
925971
/**
926972
* Something, somewhere produced an ics with an interval set to 0. Because
927973
* this means we increase the current day (or week, month) by 0, this also

0 commit comments

Comments
 (0)