Google Apps Script

Class RecurrenceRule

Represents a recurrence rule for an event series.

Note that this class also behaves like the EventRecurrence that it belongs to, allowing you to chain rule creation together like so:

 
recurrence.addDailyRule().times(3).interval(2).addWeeklyExclusion().times(2);
 
Modifiers like times(times) and interval(interval) are applied to the most recently added rule.

Methods

MethodReturn typeBrief description
addDailyExclusion()RecurrenceRuleAdds a rule that excludes occurrences on a daily basis.
addDailyRule()RecurrenceRuleAdds a rule that causes the event to recur on a daily basis.
addDate(date)EventRecurrenceAdds a rule that causes the event to recur on a specific date.
addDateExclusion(date)EventRecurrenceAdds a rule that excludes an occurrence for a specific date.
addMonthlyExclusion()RecurrenceRuleAdds a rule that excludes occurrences on a monthly basis.
addMonthlyRule()RecurrenceRuleAdds a rule that causes the event to recur on a monthly basis.
addWeeklyExclusion()RecurrenceRuleAdds a rule that excludes occurrences on a weekly basis.
addWeeklyRule()RecurrenceRuleAdds a rule that causes the event to recur on a weekly basis.
addYearlyExclusion()RecurrenceRuleAdds a rule that excludes occurrences on a yearly basis.
addYearlyRule()RecurrenceRuleAdds a rule that causes the event to recur on a yearly basis.
interval(interval)RecurrenceRuleConfigures the rule to only apply at this interval of the rule's time unit.
onlyInMonth(month)RecurrenceRuleConfigures the rule to only apply to a specific month.
onlyInMonths(months)RecurrenceRuleConfigures the rule to only apply to specific months.
onlyOnMonthDay(day)RecurrenceRuleConfigures the rule to only apply to a specific day of the month.
onlyOnMonthDays(days)RecurrenceRuleConfigures the rule to only apply to specific days of the month.
onlyOnWeek(week)RecurrenceRuleConfigures the rule to only apply to a specific week of the year.
onlyOnWeekday(day)RecurrenceRuleConfigures the rule to only apply to a specific day of the week.
onlyOnWeekdays(days)RecurrenceRuleConfigures the rule to only apply to specific days of the week.
onlyOnWeeks(weeks)RecurrenceRuleConfigures the rule to only apply to specific weeks of the year.
onlyOnYearDay(day)RecurrenceRuleConfigures the rule to only apply to a specific day of the year.
onlyOnYearDays(days)RecurrenceRuleConfigures the rule to only apply to specific days of the year.
setTimeZone(timeZone)EventRecurrenceSets the time zone for this recurrence.
times(times)RecurrenceRuleConfigures the rule to end after a given number of occurrences.
until(endDate)RecurrenceRuleConfigures the rule to end on a given date (inclusive).
weekStartsOn(day)RecurrenceRuleConfigures which day a week starts on, for the purposes of applying the rule.

Detailed documentation

addDailyExclusion()

Adds a rule that excludes occurrences on a daily basis.

 
// Creates a rule that recurs every week after the first 30 days.
 var recurrence = CalendarApp.newRecurrence().addWeeklyRule().addDailyExclusion().times(30);
 

Return

RecurrenceRule — the new RecurrenceRule


addDailyRule()

Adds a rule that causes the event to recur on a daily basis.

 
// Creates a rule that recurs every day for ten days.
 var recurrence = CalendarApp.newRecurrence().addDailyRule().times(10);
 

Return

RecurrenceRule — the new RecurrenceRule


addDate(date)

Adds a rule that causes the event to recur on a specific date.

Parameters

NameTypeDescription
dateDate

Return

EventRecurrence — this EventRecurrence for chaining


addDateExclusion(date)

Adds a rule that excludes an occurrence for a specific date.

Parameters

NameTypeDescription
dateDate

Return

EventRecurrence — this EventRecurrence for chaining


addMonthlyExclusion()

Adds a rule that excludes occurrences on a monthly basis.

By default the exclusion will be applied on the same day of the month as the first event in the series, but this can be altered by calling onlyOnMonthDay(day) or onlyOnMonthDays(days).

Return

RecurrenceRule — the new RecurrenceRule


addMonthlyRule()

Adds a rule that causes the event to recur on a monthly basis.

By default the event will recur on the same day of the month as the first event in the series, but this can be altered by calling onlyOnMonthDay(day) or onlyOnMonthDays(days).

 
// Creates a rule that recurs every month for three months.
 var recurrence = CalendarApp.newRecurrence().addMonthlyRule().times(4);
 

Return

RecurrenceRule — the new RecurrenceRule


addWeeklyExclusion()

Adds a rule that excludes occurrences on a weekly basis.

By default the exclusion will be applied on the same day of the week as the first event in the series, but this can be altered by calling onlyOnWeekday(day) or onlyOnWeekdays(days).

 
// Creates a rule that recurs every day except the first four Wednesdays.
 var recurrence = CalendarApp.newRecurrence().addDailyRule()
     .addWeeklyExclusion().onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY).times(4);
 

Return

RecurrenceRule — the new RecurrenceRule


addWeeklyRule()

Adds a rule that causes the event to recur on a weekly basis.

By default the event will recur on the same day of the week as the first event in the series, but this can be altered by calling onlyOnWeekday(day) or onlyOnWeekdays(days).

 
// Creates a rule that recurs every week for ten weeks.
 var recurrence = CalendarApp.newRecurrence().addWeeklyRule().times(10);
 

Return

RecurrenceRule — the new RecurrenceRule


addYearlyExclusion()

Adds a rule that excludes occurrences on a yearly basis.

By default the exclusion will be applied on the same day of the year as the first event in the series, but this can be altered by calling onlyOnYearDay(day) or onlyOnYearDays(days).

Return

RecurrenceRule — the new RecurrenceRule


addYearlyRule()

Adds a rule that causes the event to recur on a yearly basis.

By default the event will recur on the same day of the year as the first event in the series, but this can be altered by calling onlyOnYearDay(day) or onlyOnYearDays(days).

Return

RecurrenceRule — the new RecurrenceRule


interval(interval)

Configures the rule to only apply at this interval of the rule's time unit.

 
// Creates a rule that recurs every fourth week.
 var recurrence = CalendarApp.newRecurrence().addWeeklyRule().interval(4);
 

Parameters

NameTypeDescription
intervalIntegerthe interval in the rule's time unit

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyInMonth(month)

Configures the rule to only apply to a specific month.

 
// Creates a rule that recurs every week in February.
 var recurrence = CalendarApp.newRecurrence()
     .addWeeklyRule().onlyInMonth(CalendarApp.Month.FEBRUARY);
 

Parameters

NameTypeDescription
monthMonththe month

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyInMonths(months)

Configures the rule to only apply to specific months.

 
// Creates a rule that recurs every week in February and March.
 var recurrence = CalendarApp.newRecurrence()
     .addWeeklyRule().onlyInMonths([CalendarApp.Month.FEBRUARY, CalendarApp.Month.MARCH]);
 

Parameters

NameTypeDescription
monthsMonth[]the months

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyOnMonthDay(day)

Configures the rule to only apply to a specific day of the month.

 
// Creates a rule that recurs every month on the fifth day of the month.
 var recurrence = CalendarApp.newRecurrence().addMonthlyRule().onlyOnMonthDay(5);
 

Parameters

NameTypeDescription
dayIntegerthe day of the month

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyOnMonthDays(days)

Configures the rule to only apply to specific days of the month.

 
// Creates a rule that recurs every month on the first and fifteenth day of the month.
 var recurrence = CalendarApp.newRecurrence().addMonthlyRule().onlyOnMonthDays([1, 15]);
 

Parameters

NameTypeDescription
daysInteger[]the days of the month

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyOnWeek(week)

Configures the rule to only apply to a specific week of the year.

 
// Creates a rule that recurs on the fifth week of every year.
 var recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeek(5);
 

Parameters

NameTypeDescription
weekIntegerthe week

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyOnWeekday(day)

Configures the rule to only apply to a specific day of the week.

 
// Creates a rule that recurs every week on Wednesdays.
 var recurrence = CalendarApp.newRecurrence()
     .addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY);
 

Parameters

NameTypeDescription
dayWeekdaythe day of the week

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyOnWeekdays(days)

Configures the rule to only apply to specific days of the week.

 
// Creates a rule that recurs every week on Tuesdays and Thursdays.
 var recurrence = CalendarApp.newRecurrence()
     .addWeeklyRule().onlyOnWeekdays(
         [CalendarApp.Weekday.TUESDAY, CalendarApp.Weekday.THURSDAY]);
 

Parameters

NameTypeDescription
daysWeekday[]the days of the week

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyOnWeeks(weeks)

Configures the rule to only apply to specific weeks of the year.

 
// Creates a rule that recurs on the fifth and tenth weeks of every year.
 var recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeeks([5, 10]);
 

Parameters

NameTypeDescription
weeksInteger[]the weeks

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyOnYearDay(day)

Configures the rule to only apply to a specific day of the year.

 
// Creates a rule that recurs every year on February 15 (the 46th day).
 var recurrence = CalendarApp.newRecurrence().addYearlyRule().onlyOnYearDay(46);
 

Parameters

NameTypeDescription
dayIntegerthe day of the year

Return

RecurrenceRule — this RecurrenceRule for chaining


onlyOnYearDays(days)

Configures the rule to only apply to specific days of the year.

 
// Creates a rule that recurs every year on January 20 and February 15.
 var recurrence = CalendarApp.newRecurrence().addYearlyRule().onlyOnYearDay([20, 46]);
 

Parameters

NameTypeDescription
daysInteger[]the days of the year

Return

RecurrenceRule — this RecurrenceRule for chaining


setTimeZone(timeZone)

Sets the time zone for this recurrence. This affects the date and time that events recur on, and whether the event shifts with daylight savings time. Defaults to the calendar's time zone.

Parameters

NameTypeDescription
timeZoneStringthe time zone, specified in "long" format (e.g., 'America/New_York', as listed by Joda.org)

Return

EventRecurrence — this EventRecurrence for chaining


times(times)

Configures the rule to end after a given number of occurrences.

 
// Creates a rule that recurs every day for ten days.
 var recurrence = CalendarApp.newRecurrence().addDailyRule().times(10);
 

Parameters

NameTypeDescription
timesIntegerthe number of times to recur

Return

RecurrenceRule — this RecurrenceRule for chaining


until(endDate)

Configures the rule to end on a given date (inclusive).

 
// Creates a rule that recurs every day through the end of 2013.
 var recurrence = CalendarApp.newRecurrence()
     .addDailyRule().until(new Date('December 31, 2013'));
 

Parameters

NameTypeDescription
endDateDate

Return

RecurrenceRule — this RecurrenceRule for chaining


weekStartsOn(day)

Configures which day a week starts on, for the purposes of applying the rule.

 
// Creates a weekly rule where weeks start on Monday.
 var recurrence = CalendarApp.newRecurrence()
     .addWeeklyRule().weekStartsOn(CalendarApp.Weekday.MONDAY);
 

Parameters

NameTypeDescription
dayWeekdaythe day on which the week will start

Return

RecurrenceRule — this RecurrenceRule for chaining

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.