I create an EKEvent in calendar with a recurrence pattern.
EKRecurrenceRule <0x6000000b0980> RRULE FREQ=WEEKLY;INTERVAL=2;BYDAY=SU,MO;WKST=SU
The event is created on sunday May 13, 2018 and should appear every 2 weeks on Sunday and Monday.
As per the recurrence rule, the next occurrence dates are May 14 2018, May 27 2018 , May 28 2018 and so on
I'm looking for a way to get the next occurrence date based on the recurrence rule which in this case is May 14 2018.
I can get the current occurrence date by accessing the event.occurrenceDate;
However I couldn't find a way to get the next occurrence date.
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.startDate = self.startTime;
event.endDate = [event.startDate dateByAddingMinutes:self.durationMins];
event.recurrenceRules = [NSArray arrayWithObject:[[EKRecurrenceRule alloc] initWithString:@"FREQ=WEEKLY;INTERVAL=2;BYDAY=SU,MO;"]];
NSDate *currentOccurence = event.occurrenceDate;
NSDate *nextOccurence = ?? ;
I tried by doing this:
Get all the events for the month, and compare each event with the current occurring event. If they matches, get the next event occurring date.
NSPredicate * predicate = [self.eventStore predicateForEventsWithStartDate:event.startDate endDate:[event.startDate dateByAddingMonths:1] calendars:@[[self.eventStore calendarWithIdentifier:self.selectedCalendarIdentifier]]];
NSArray * events = [self.eventStore eventsMatchingPredicate:predicate];
for (EKEvent * temp in events) {
//get the next event by comparing this event occurrence with current event occurrence date
}
and I see the events array did not have the correct occurrence dates. It is missing some occurrence dates.
I can also reproduce this in the native calendar app. I created a test event with same recurrence pattern which is occur every 2 weeks on sun, mon.
However it is only displaying on every week monday.
As you can see in the monthly calendar the event should appear only at May 13, May 14, and the next occurrence May 27, May 28, and next occurrence June 10, June 11 based on the recurrence pattern, but it is appearing at May 13 (Correct), May 21 (wrong) , May 27 (correct) , June 4 (wrong).