You can think of a recurrence pattern as a way to describe a particular schedule. It contains just enough information to build a list of occurrences (date and times) according to a given schedule. A recurrence pattern may contain recurrence rules that describe the various cycles that combine to form the overall pattern. In general, more complex a Recurrence Pattern is, the more Recurrence Rules it will contain.
Recurrence patterns can include exceptions (do not confuse with exceptions that represent errors that occur during application execution). Exceptions can add or remove occurrence dates to the original pattern. Exceptions can be specified as explicit occurrences or as a pattern themselves. Examples of recurrence patterns with exceptions:
- Every 2nd Friday, except in June-August
- Every 1st of the month, except in January, when it should be on the 2nd of January.
Recurrence patterns most often are periodic, but they don’t have to be. A recurrence pattern can be completely described just as a set of predefined occurrence dates and times.
The iCalendar RFC defines “components”, such as such as VEVENT or VTODO that represent events or tasks. The components can have properties such as start date time, description, location, attendees and recurrence. Therefore a recurrence pattern normally exists as a property of a recurring task or an event.
Recurrence pattern properties defined by iCalendar are:
- DTSTART - identifies start date time of the pattern (and represents the first occurrence if not excluded explicitly)
- RRULE - specifies a repeating rule for a recurrence set
- RDATE - defines a list of date/times to include in a recurrence set
- EXRULE - specifies a repeating rule for exceptions from a recurrence set
- EXDATE - defines a list of date/time exceptions from a recurrence set.
Only DTSTART is required and there must be only one DTSTART. All other properties are optional and can be specified more than once.
Aspose.iCalendar will take a string in iCalendar format and read the recurrence pattern into a RecurrencePattern object. The string can be a complete description of an iCalendar component (for example, complete VEVENT) or it can be just a fragment that contains only the recurrence pattern.
Once the recurrence pattern is loaded into a RecurrencePattern object, you can:
- Examine and modify the pattern programmatically via methods and properties provided by Aspose.iCalendar
- Generate occurrence dates/times in a specified date range.
- Save the pattern in iCalendar format.
In the following example, the RRULE part contains the recurrence rule.
//Ten team meetings, every Monday at 10am.
RecurrencePattern pattern = new RecurrencePattern(
"DTSTART:20040301T100000\n" +
"RRULE:FREQ=WEEKLY;COUNT=10;BYDAY=MO");
DateArray dates = pattern.GenerateOccurrences();