iCalendar RFC 2445

Recurrence Patterns in the Real World

A recurrence pattern describes the rules when the event occurs. A recurrence pattern engine such as Aspose iCalendar is needed to calculate the dates and times of the occurrences for a given recurrence pattern. We encounter schedules or recurrence patterns in many situations, for example:

  • Ten team meetings, every Monday at 10am.
  • Process salary payment on the last work day every month.
  • Check patient’s temperature every day for two weeks.
  • Go to the gym on Monday, Wednesday and Friday.
  • Run backup every 4 hours on work days.
  • Generate sales report on …
  • Update website statistics every …

Almost any event that occurs periodically can be represented as a recurrence pattern. For example, the following code will return an array containing ten occurrences of the previous team meeting example:

CalendarRecurrence recurrencePattern = new CalendarRecurrence("DTSTART:20040301T100000\nRRULE:FREQ=WEEKLY;COUNT=10;BYDAY=MO");
DateCollection expectedDates = recurrencePattern.generateOccurrences();
System.out.println("expectedDates.Count = " + expectedDates.size());
for (int i = 0; i < expectedDates.size(); i++) {
    System.out.println("DateTime = " + sdf.format(expectedDates.getItem(i)));
}