Menu

Evaluate RecurrenceRule with modified instances

Anonymous
2016-04-13
2016-05-01
  • Anonymous

    Anonymous - 2016-04-13

    I created a recurring event and changed the time of some instances. Using the DateIterator from the RecurrenceRule gives me the dates of the event ignoring the instances I changed. What I want is to get all actual dates of the event, meaning the original one where there isn't a modified instance and the modified instance where there is one. Is there a nice way to do that in biweekly?

     
  • Michael Angstadt

    Hello,

    Can you elaborate on how you changed the time of some instances? Can you provide a code sample?

    Thank you,
    Mike

     
    • Anonymous

      Anonymous - 2016-04-19

      Hi Mike,
      I used the google calendar and manually changed the time of some instances, then imported the iCal file. In an automatic way I would create a new VEvent, set the recurrenceId to the date I want to change, and then set a new start and end for the event.

      The following code seems to work for my example iCal-file. It works by iterating over the recurrenceRule, excluding all the dates where the iCal contains an event with a matching recurrenceId:

      HashSet<ICalDate> datesWithModifiedInstances = createDateSetFromRecurrenceIds(events);
              for (VEvent event : events) {
                  RecurrenceRule recurrenceRule = event.getRecurrenceRule();
                  if (recurrenceRule == null) {
                      if (!event.getDateStart().getValue().before(lowerBound)) {
                          // FOUND A DATE
                      }
                  } else {
                      DateIterator dateIterator = recurrenceRule.getDateIterator(event.getDateStart().getValue());
                      Date currentDate = lowerBound;
                      dateIterator.advanceTo(currentDate);
                      while (dateIterator.hasNext()) {
                          currentDate = dateIterator.next();
                          if (datesWithModifiedInstances.contains(new ICalDate(currentDate))) {
                              // exclude all modified recurrence instances
                              continue;
                          }
                          if (beginsAfterUpperBound(upperBound, currentDate)) {
                              break;
                          }
                          // FOUND A DATE
                      }
                  }
              }
      
       

      Last edit: Anonymous 2016-04-20
      • Michael Angstadt

        Thank you for the update. Good to hear that you figured it out. Please let me know if you have any other questions.

         

Anonymous
Anonymous

Add attachments
Cancel