1

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.

enter image description here

enter image description here

enter image description here

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).

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • A quick search reveals that you are not the first to ask this and so far no one has an answer. – rmaddy May 13 '18 at 18:21
  • Is there a bug on calendar kit ? I created an event on the native calendar (occur every 2 weeks and occur on sunday,monday), and the calendar is showing the event on wrong days. I updated my question, please have a look at it. If it appears correct on calendar, this approach can solve my issue. @rmaddy – Teja Nandamuri May 13 '18 at 20:08
  • I see the same bug in the Calendar app. But if you create the same event with a start day of tomorrow (Monday) and set it for every Monday/Tuesday, it works as expected. It seems to get the "every two weeks" incorrect if the start day is "today" and you select today's day of the week as one of the options. – rmaddy May 13 '18 at 21:05

0 Answers0