Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetOccurrences should not cache the results of a previous evaluation #223

Closed
rianjs opened this issue Jan 16, 2017 · 2 comments
Closed

GetOccurrences should not cache the results of a previous evaluation #223

rianjs opened this issue Jan 16, 2017 · 2 comments
Labels

Comments

@rianjs
Copy link
Collaborator

rianjs commented Jan 16, 2017

Recurrable components are mutable -- rules can be created at will, so caching the result of a previous computation is potentially invalid:

[Test]
public void AddExDateToEventAfterGetOccurrencesShouldRecomputeResult()
{
    var searchStart = _now.AddDays(-1);
    var searchEnd = _now.AddDays(7);
    var e = GetEventWithRecurrenceRules();
    var occurrences = e.GetOccurrences(searchStart, searchEnd);
    Assert.IsTrue(occurrences.Count == 5);

    var exDate = _now.AddDays(1);
    var period = new Period(new CalDateTime(exDate));
    var periodList = new PeriodList {period};
    e.ExceptionDates.Add(periodList);
    occurrences = e.GetOccurrences(searchStart, searchEnd);
    Assert.IsTrue(occurrences.Count == 4);

    //Specifying just a date should "black out" that date
    var excludeTwoDaysFromNow = _now.AddDays(2).Date;
    period = new Period(new CalDateTime(excludeTwoDaysFromNow));
    periodList.Add(period);
    occurrences = e.GetOccurrences(searchStart, searchEnd);
    Assert.IsTrue(occurrences.Count == 3);
}

private static readonly DateTime _now = DateTime.Now;
private static readonly DateTime _later = _now.AddHours(1);
private static Event GetEventWithRecurrenceRules()
{
    var dailyForFiveDays = new RecurrencePattern(FrequencyType.Daily, 1)
    {
        Count = 5,
    };

    var calendarEvent = new Event
    {
        Start = new CalDateTime(_now),
        End = new CalDateTime(_later),
        RecurrenceRules = new List<IRecurrencePattern> { dailyForFiveDays },
        Resources = new HashSet<string>(new[] {"Foo", "Bar", "Baz"}),
    };
    return calendarEvent;
}

EXDATE values that specify only a date should "black out" occurrences where the start time of the event falls on that date.

@rianjs rianjs added the bug label Jan 16, 2017
rianjs pushed a commit that referenced this issue Jan 16, 2017
…because rules and data governing recurrence sets are mutable after the event is created. #223
@rianjs
Copy link
Collaborator Author

rianjs commented Jan 16, 2017

de1f045

Available in nuget version 2.2.29

@rianjs rianjs closed this as completed Jan 16, 2017
@LucBrainpact
Copy link

I've run across an issue with the current fix today:
An EXDATE with datetime at midnight also "blacks out" all occurrences that fall on that date.

BEGIN:VEVENT
DTEND;TZID=Europe/Amsterdam:20180308T040000
DTSTAMP:20180322T094247Z
DTSTART;TZID=Europe/Amsterdam:20180308T040000
EXDATE:20180309T000000
RRULE:FREQ=HOURLY;INTERVAL=4
SEQUENCE:0
UID:9f449bf5-c4ec-48cb-8a29-439d9088e14c
END:VEVENT

In the example above all occurrences on March 9th are excluded, the expected result was only the occurrence at midnight was excluded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants