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

Multiple Recurrence Patterns (RecurrenceRules & ExceptionRules) are ignored #524

Closed
OlegBarkov opened this issue Jul 27, 2021 · 5 comments
Closed

Comments

@OlegBarkov
Copy link
Contributor

OlegBarkov commented Jul 27, 2021

Nuget version: 4.2.0
Observed behavior: If multiple RecurrenceRules and/or ExceptionRules are added to the Event, only the first rule is taken into account. Others are ignored.
Expected behavior: All RecurrenceRules and ExceptionRules should be applied.

Example 1:

var rrule = new RecurrencePattern("FREQ=DAILY;INTERVAL=1"); // Event occurs every day
var exception1 = new RecurrencePattern("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO"); // Except Mondays
var exception2 = new RecurrencePattern("FREQ=MONTHLY;INTERVAL=1;BYDAY=1TU"); // Except the first Tuesday of each month
var startDate = DateTime.Parse("07/30/2021");
var endDate = DateTime.Parse("08/07/2021");

var iCalevent = new CalendarEvent
{
    Start = new CalDateTime(2021, 8, 1),
    RecurrenceRules = new List<RecurrencePattern> { rrule },
    ExceptionRules = new List<RecurrencePattern>() { exception1, exception2 }
};
var calendar = new Calendar();
calendar.Events.Add(iCalevent);

var occurrences = calendar.GetOccurrences(startDate, endDate).AsEnumerable();
foreach (var occurrence in occurrences)
{
    Console.WriteLine($"{occurrence.Period.StartTime:dddd, MMMM dd, yyyy h:mm:ss tt}");
}
   /*
    * Actual output:
    * Sunday, August 01, 2021 12:00:00 AM
    *                                       <-- No Monday is expected due to exception1
    * Tuesday, August 03, 2021 12:00:00 AM  <-- this is UNEXPECTED since it is the first Tuesday of the month (see exception2)
    * Wednesday, August 04, 2021 12:00:00 AM
    * Thursday, August 05, 2021 12:00:00 AM
    * Friday, August 06, 2021 12:00:00 AM             
    */

Example 2:

var rrule1 = new RecurrencePattern("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO"); // Event occurs on each Monday
var rrule2 = new RecurrencePattern("FREQ=MONTHLY;INTERVAL=1;BYDAY=1TU"); // Event occurs on the first Tuesday of each month
var startDate1 = DateTime.Parse("08/01/2021");
var endDate1 = DateTime.Parse("09/01/2021");

var iCalevent1 = new CalendarEvent
{
    Start = new CalDateTime(2021, 8, 1),
    RecurrenceRules = new List<RecurrencePattern> { rrule1, rrule2 }
};
var calendar1 = new Calendar();
calendar1.Events.Add(iCalevent1);

var occurrences1 = calendar1.GetOccurrences(startDate1, endDate1).AsEnumerable().OrderBy(x => x.Period.StartTime);
foreach (var occurrence in occurrences1)
{
    Console.WriteLine($"{occurrence.Period.StartTime:dddd, MMMM dd, yyyy h:mm:ss tt}");
}

            /*
            * Actual output:
            * Monday, August 02, 2021 12:00:00 AM
            *                                       <-- Expected Tuesday, August 03, 2021 12:00:00 AM
            * Monday, August 09, 2021 12:00:00 AM
            * Monday, August 16, 2021 12:00:00 AM
            * Monday, August 23, 2021 12:00:00 AM
            * Monday, August 30, 2021 12:00:00 AM
            */

OlegBarkov added a commit to OlegBarkov/ical.net that referenced this issue Jul 27, 2021
BUG FIX: Multiple Recurrence Patterns (RecurrenceRules & ExceptionRules) are ignored ical-org#524
@billyjacobs2014
Copy link

billyjacobs2014 commented Aug 11, 2021

@OlegBarkov I have a question you may be able to answer. I was under the impression that if I had something like the following, the call to GetOccurrences would return the actual times of each occurrence, but it appears to only return the list of dates on which the occurrences will occur. Assuming today is 8/11, is what is being returned expected?

Actual
08/12/2021
08/13/2021
... skip for brevity
08/18/2021

Expected By Me
08/12/2021 11:00:00, 08/12/2021 14:00:00
08/13/2021 11:00:00, 08/13/2021 14:00:00
.... skip for brevity
08/18/2021 11:00:00, 08/18/2021 14:00:00

        // Every Day at hour 11 and hour 14, for 14 occurrences
        var tomorrow = DateTime.Now.Date.AddDays(1);
        var rrule = new RecurrencePattern(FrequencyType.Daily, 1) 
        {
            Count = 14,
            ByHour = new List<int> { 11, 14}
        };

        var calendarEvent = new CalendarEvent
        {
            Start = new CalDateTime(tomorrow), 
            RecurrenceRules = new List<RecurrencePattern> { rrule },
        };

        var calendar = new Calendar();
        calendar.Events.Add(calendarEvent);
        // calendar.RecurrenceEvaluationMode = RecurrenceEvaluationModeType.AdjustAutomatically;
        var occurrences = calendar.GetOccurrences(new CalDateTime(DateTime.Now.Date), new CalDateTime(DateTime.Now.Date.AddDays(50)));

@OlegBarkov
Copy link
Contributor Author

@billyjacobs2014 I think you are correct, GetOccurrences should return times of occurrences not only dates. But this looks like a separate issue.

@kibblewhite
Copy link

I have also just arrived at the same issue as OlegBarkov has explained at the opening of this issue.

@rootGst
Copy link

rootGst commented Aug 25, 2021

@billyjacobs2014 this happens, when the time of day for start is set to 00:00:00. I agree with @OlegBarkov that this might be a separate issues

@tuannla07
Copy link

Can i know when we have the next release for this issue ?

@axunonb axunonb closed this as completed Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants