diff --git a/Ical.Net.Tests/RecurrenceTests.cs b/Ical.Net.Tests/RecurrenceTests.cs index 3421b831..0b5a4900 100644 --- a/Ical.Net.Tests/RecurrenceTests.cs +++ b/Ical.Net.Tests/RecurrenceTests.cs @@ -3916,22 +3916,35 @@ public void TestDtStartTimezone(string? tzId) Assert.That(expectedStartTimes.SequenceEqual(occurrencesStartTimes), Is.True); } - [Test] - [TestCase(null, false)] - [TestCase(0, true)] - [TestCase(1000, true)] - [TestCase(1440, false)] - public void TestMaxIncrementCount(int? limit, bool expectException) - { - var ical = """ + // Between 00:59 and 00:00 there's a gap of 1380 minutes, which is 690 increments. + private const string TestMaxIncrementCountWithGaps = """ BEGIN:VCALENDAR BEGIN:VEVENT DTSTART:20250305T000000 - RRULE:FREQ=MINUTELY;BYHOUR=0;COUNT=100 + RRULE:FREQ=MINUTELY;INTERVAL=2;BYHOUR=0;COUNT=100 END:VEVENT END:VCALENDAR """; + private const string TestMaxIncrementCountWithoutGaps = """ + BEGIN:VCALENDAR + BEGIN:VEVENT + DTSTART:20250305T000000 + RRULE:FREQ=DAILY;INTERVAL=10;COUNT=100 + END:VEVENT + END:VCALENDAR + """; + + [Test] + [TestCase(null, TestMaxIncrementCountWithGaps, false)] + [TestCase(0, TestMaxIncrementCountWithGaps, true)] + [TestCase(1, TestMaxIncrementCountWithGaps, true)] + [TestCase(689, TestMaxIncrementCountWithGaps, true)] + [TestCase(690, TestMaxIncrementCountWithGaps, false)] + [TestCase(0, TestMaxIncrementCountWithoutGaps, false)] + [TestCase(1, TestMaxIncrementCountWithoutGaps, false)] + public void TestMaxIncrementCount(int? limit, string ical, bool expectException) + { var cal = Calendar.Load(ical); var options = new EvaluationOptions diff --git a/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs b/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs index d9ba415a..dd2cc0f4 100644 --- a/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs +++ b/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs @@ -192,10 +192,11 @@ private IEnumerable EnumerateDates(CalDateTime originalDate, CalDat dateCount++; } - noCandidateIncrementCount++; if (noCandidateIncrementCount > options?.MaxUnmatchedIncrementsLimit) throw new EvaluationLimitExceededException(); + noCandidateIncrementCount++; + IncrementDate(ref intervalRefTime, pattern, pattern.Interval); } }