The recurrence-related types and classes (RecurrenceFrequency
, RecurrenceDayOfWeek
, RecurrenceWeekday
, RecurrenceEnd
, and RecurrenceRule
) allow you to define and manage recurring patterns for events and reminders in the Scripting
app. These types and classes make it possible to set up recurrence intervals, specify days or months for recurring patterns, and define end conditions.
RecurrenceFrequency
RecurrenceFrequency
defines the frequency with which an event or reminder repeats. The frequency can be one of the following values:
daily
: Repeats every day.weekly
: Repeats every week.monthly
: Repeats every month.yearly
: Repeats every year.This type is used as a property within the RecurrenceRule
class to specify how often the recurrence should occur.
Example Usage:
RecurrenceWeekday
RecurrenceWeekday
is an enumeration representing the days of the week. It allows you to specify which day or days an event should recur on within a weekly pattern. The values are:
"sunday"
, "monday"
, "tuesday"
, "wednesday"
, "thursday"
, "friday"
, "saturday"
Example Usage:
RecurrenceDayOfWeek
RecurrenceDayOfWeek
allows for specifying a particular weekday, optionally combined with a weekNumber
. This type is useful in more complex weekly recurrence patterns where you want to specify both the weekday and its occurrence within a month (like the second Tuesday of each month).
RecurrenceDayOfWeek
can either be:
RecurrenceWeekday
, orweekday
: A RecurrenceWeekday
(e.g., "monday"
)weekNumber
: A number indicating which occurrence of the weekday (positive or negative for backward counting). For example, 1
is the first occurrence, -1
is the last occurrence.Example Usage:
RecurrenceEnd
RecurrenceEnd
defines when a recurrence rule should stop. It provides two options for ending a recurrence:
fromCount(count: number)
: Ends the recurrence after a specified number of occurrences.fromDate(date: Date)
: Ends the recurrence on a specific date.This is useful when setting a limit for how many times the event or reminder should recur.
fromCount(count): Creates a count-based recurrence end.
fromDate(date): Creates a date-based recurrence end.
RecurrenceRule
RecurrenceRule
defines the complete pattern for a recurring event or reminder, including its frequency, interval, specific days, months, and an optional end condition.
string
– Unique identifier for the recurrence rule.RecurrenceFrequency
– Frequency of recurrence (daily, weekly, monthly, yearly).number
– Interval between recurrences (e.g., every 2 weeks). Must be greater than 0.RecurrenceEnd (optional)
– Specifies the end of the recurrence.number
– The day treated as the start of the week.RecurrenceDayOfWeek[] (optional)
– Specific days of the week for the recurrence.number[] (optional)
– Specific days of the month (values from 1 to 31, or -1 to -31).number[] (optional)
– Specific days of the year.number[] (optional)
– Specific weeks of the year.number[] (optional)
– Specific months of the year.number[] (optional)
– Filters recurrences to specific positions within the frequency period.RecurrenceRule
instance using the specified options.
daily
, weekly
).RecurrenceDayOfWeek
.To create a recurring event or reminder with these types, follow these steps:
RecurrenceFrequency
to specify how often the event or reminder should occur.RecurrenceWeekday
, RecurrenceDayOfWeek
, daysOfTheMonth
, etc., to specify exact days.interval
to control how often the event or reminder should recur based on the frequency.RecurrenceEnd
to specify when the recurrence should stop.RecurrenceRule.create()
with the configured options.This example creates a RecurrenceRule
for an event that occurs every second Tuesday each month, ending after six occurrences.