RecurrenceRule

Represents a recurrence rule for an event series.

Note that this class also behaves like the `https://developers.google.com/apps-script/reference/calendar/event-recurrence` that it belongs to,
allowing you to chain rule creation together like so:

```javascript
const recurrence = CalendarApp.newRecurrence().addDailyRule().times(3).interval(2).addWeeklyExclusion().times(2);
```
Modifiers like `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#times(Integer)` and `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#interval(Integer)` are applied to the most recently added rule.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addDailyExclusion()` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Adds a rule that excludes occurrences on a daily basis. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addDailyRule()` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Adds a rule that causes the event to recur on a daily basis. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addDate(Date)` | `https://developers.google.com/apps-script/reference/calendar/event-recurrence` | Adds a rule that causes the event to recur on a specific date. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addDateExclusion(Date)` | `https://developers.google.com/apps-script/reference/calendar/event-recurrence` | Adds a rule that excludes an occurrence for a specific date. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addMonthlyExclusion()` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Adds a rule that excludes occurrences on a monthly basis. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addMonthlyRule()` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Adds a rule that causes the event to recur on a monthly basis. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addWeeklyExclusion()` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Adds a rule that excludes occurrences on a weekly basis. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addWeeklyRule()` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Adds a rule that causes the event to recur on a weekly basis. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addYearlyExclusion()` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Adds a rule that excludes occurrences on a yearly basis. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#addYearlyRule()` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Adds a rule that causes the event to recur on a yearly basis. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#interval(Integer)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply at this interval of the rule's time unit. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyInMonth(Month)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to a specific month. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyInMonths(Month)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to specific months. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnMonthDay(Integer)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to a specific day of the month. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnMonthDays(Integer)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to specific days of the month. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnWeek(Integer)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to a specific week of the year. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnWeekday(Weekday)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to a specific day of the week. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnWeekdays(Weekday)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to specific days of the week. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnWeeks(Integer)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to specific weeks of the year. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnYearDay(Integer)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to a specific day of the year. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnYearDays(Integer)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to only apply to specific days of the year. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#setTimeZone(String)` | `https://developers.google.com/apps-script/reference/calendar/event-recurrence` | Sets the time zone for this recurrence. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#times(Integer)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to end after a given number of occurrences. |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#until(Date)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures the rule to end on a given date (inclusive). |
| `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#weekStartsOn(Weekday)` | `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` | Configures 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.

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

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- the new RecurrenceRule

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addDailyRule()`

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

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

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- the new RecurrenceRule

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addDate(date)`

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `date` | `Date` |   |

#### Return


`https://developers.google.com/apps-script/reference/calendar/event-recurrence` --- this EventRecurrence for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addDateExclusion(date)`

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `date` | `Date` |   |

#### Return


`https://developers.google.com/apps-script/reference/calendar/event-recurrence` --- this EventRecurrence for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addMonthlyExclusion()`

Adds a rule that excludes occurrences on a monthly basis.

By default the exclusion is applied on the same day of the month as the first event in the
series, but this can be altered by calling `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnMonthDay(Integer)` or `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnMonthDays(Integer)`.

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- the new RecurrenceRule

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addMonthlyRule()`

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

By default the event recurs on the same day of the month as the first event in the series,
but this can be altered by calling `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnMonthDay(Integer)` or `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnMonthDays(Integer)`.

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

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- the new RecurrenceRule

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addWeeklyExclusion()`

Adds a rule that excludes occurrences on a weekly basis.

By default the exclusion is applied on the same day of the week as the first event in the
series, but this can be altered by calling `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnWeekday(Weekday)` or `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnWeekdays(Weekday)`.

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

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- the new RecurrenceRule

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addWeeklyRule()`

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

By default the event recurs on the same day of the week as the first event in the series,
but this can be altered by calling `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnWeekday(Weekday)` or `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnWeekdays(Weekday)`.

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

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- the new RecurrenceRule

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addYearlyExclusion()`

Adds a rule that excludes occurrences on a yearly basis.

By default the exclusion is applied on the same day of the year as the first event in the
series, but this can be altered by calling `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnYearDay(Integer)` or `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnYearDays(Integer)`.

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- the new RecurrenceRule

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `addYearlyRule()`

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

By default the event recurs on the same day of the year as the first event in the series,
but this can be altered by calling `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnYearDay(Integer)` or `https://developers.google.com/apps-script/reference/calendar/recurrence-rule#onlyOnYearDays(Integer)`.

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- the new RecurrenceRule

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `interval(interval)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `interval` | `Integer` | the interval in the rule's time unit |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyInMonth(month)`

Configures the rule to only apply to a specific month.

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `month` | `https://developers.google.com/apps-script/reference/base/month.html` | the month |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyInMonths(months)`

Configures the rule to only apply to specific months.

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `months` | `https://developers.google.com/apps-script/reference/base/month.html` | the months |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyOnMonthDay(day)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `day` | `Integer` | the day of the month |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyOnMonthDays(days)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `days` | `Integer[]` | the days of the month |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyOnWeek(week)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `week` | `Integer` | the week |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyOnWeekday(day)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `day` | `https://developers.google.com/apps-script/reference/base/weekday.html` | the day of the week |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyOnWeekdays(days)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `days` | `https://developers.google.com/apps-script/reference/base/weekday.html` | the days of the week |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyOnWeeks(weeks)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `weeks` | `Integer[]` | the weeks |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyOnYearDay(day)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `day` | `Integer` | the day of the year |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `onlyOnYearDays(days)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `days` | `Integer[]` | the days of the year |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- 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

| Name | Type | Description |
|---|---|---|
| `timeZone` | `String` | the time zone, specified in "long" format (e.g., 'America/New_York', as listed by [Joda.org](http://joda-time.sourceforge.net/timezones.html)) |

#### Return


`https://developers.google.com/apps-script/reference/calendar/event-recurrence` --- this EventRecurrence for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `times(times)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `times` | `Integer` | the number of times to recur |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

*** ** * ** ***

### `until(endDate)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `endDate` | `Date` |   |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes) or appropriate scopes from the [related REST API](https://developers.google.com/identity/protocols/googlescopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `weekStartsOn(day)`

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

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `day` | `https://developers.google.com/apps-script/reference/base/weekday.html` | the day on which the week starts |

#### Return


`https://developers.google.com/apps-script/reference/calendar/recurrence-rule#` --- this RecurrenceRule for chaining