rianjs / ical.net

ical.NET - an open source iCal library for .NET
MIT License
782 stars 230 forks source link

EventEvaluator.Evaluate returns dates earlier than periodStart. #478

Open ghost opened 4 years ago

ghost commented 4 years ago

Nuget version: v4.1.11 Observed behavior:: Four periods are returned after evaluating, even though they fall before the periodStart date. Expected behavior: Zero periods since the last one is on November 3rd, 2019 and periodStart starts from December 1st, 2019.

An event string is made that created a recurrence for every first, second and fourth Sunday for four times starting from October 6th, 2019. These dates are:

I evaluate this against a periodStart of December 1st, 2019 and a periodEnd of December 1st, 2020. I expect no periods to return, but all the periods above still get returned.

Here is a unit test that showcases the problem:

[TestMethod]
public void HasNoOccurencerAfter_MONTHLY_COUNT4_THRICEAMONTH()
{
    var fromDate = new DateTime(2019, 12, 01);

    var eventString = $"BEGIN:VEVENT\nDTSTART:20191006T000000Z\nRRULE:FREQ=MONTHLY;INTERVAL=1;COUNT=4;WKST=MO;BYDAY=+1SU,+2SU,+4SU\nEND:VEVENT";
    var vEvents = Calendar.Load<CalendarEvent>(eventString);
    var evt = vEvents.FirstOrDefault();

    var evtEval = new EventEvaluator(evt);
    var periods = evtEval.Evaluate(evt.Start, fromDate, fromDate.AddYears(1), false);

    Assert.IsFalse(periods.Any());
}
ghost commented 4 years ago

Has anyone been able to look into this by chance?