Skip to content

Commit

Permalink
Fix inverted limiting behavior of BYMONTHDAY (ical-org#730)
Browse files Browse the repository at this point in the history
* Fix ical-org#728: wrong behavior of `BYMONTHDAY` limitting behaviour.

* Test: Add more test cases, i.e. covering BYYEARDAY, BYHOUR, BYMINUTE, BYSECOND limit behaviour.
  • Loading branch information
minichma authored Feb 15, 2025
1 parent 9988a1c commit 70c7c82
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Ical.Net.Tests/Calendars/Recurrence/RecurrenceTestCases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,18 @@ RRULE:FREQ=YEARLY;BYWEEKNO=1;BYDAY=MO,TU;INTERVAL=3;UNTIL=20320101
DTSTART:20241231
INSTANCES:20241231,20280103,20280104,20301230,20301231

# BYMONTHDAY with limit behaviour; reproduces #728 as reported by pinkfloydx33
RRULE:FREQ=DAILY;BYMONTHDAY=20,-2;UNTIL=20250401
DTSTART:20250220
INSTANCES:20250220,20250227,20250320,20250330

# BYYEARDAY with limit behaviour; BYHOUR limit behaviour
RRULE:FREQ=HOURLY;BYHOUR=0;BYYEARDAY=360,-2;UNTIL=20260101T000000
DTSTART:20251220T000000
INSTANCES:20251226T000000,20251230T000000

# BYHOUR, BYMINUTE, BYSECOND limit behaviour
# note that the max number of increments is 1000, so we can only observer a limited time span
RRULE:FREQ=SECONDLY;BYHOUR=1,2;BYMINUTE=3,4,59;BYSECOND=5,6;UNTIL=20250216T020500
DTSTART:20250216T015905
INSTANCES:20250216T015905,20250216T015906,20250216T020305,20250216T020306,20250216T020405,20250216T020406
5 changes: 3 additions & 2 deletions Ical.Net/Evaluation/RecurrencePatternEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,12 @@ select monthDay > 0
}
return monthDayDates;
}

// Limit behavior
for (var i = dates.Count - 1; i >= 0; i--)
{
var date = dates[i];
var keepDate = true;
var keepDate = false;
for (var j = 0; j < pattern.ByMonthDay.Count; j++)
{
var monthDay = pattern.ByMonthDay[j];
Expand All @@ -479,7 +480,7 @@ select monthDay > 0

if (newDate.Day.Equals(date.Day))
{
keepDate = false;
keepDate = true;
break;
}
}
Expand Down

0 comments on commit 70c7c82

Please sign in to comment.