📅  最后修改于: 2023-12-03 14:40:00.945000             🧑  作者: Mango
CalendarApp.newRecurrence()
is a method in Google Apps Script that creates a new Recurrence object for a calendar event. A Recurrence object is used to define a repeating pattern for an event, such as once a week, every weekday, every other Tuesday, etc.
CalendarApp.newRecurrence();
A new Recurrence object.
// Create a new event recurrence that repeats weekly on Monday, Wednesday, and Friday.
var recurrence = CalendarApp.newRecurrence().addWeeklyRule()
.onlyOnWeekdays([CalendarApp.Weekday.MONDAY,
CalendarApp.Weekday.WEDNESDAY,
CalendarApp.Weekday.FRIDAY]);
In this example, CalendarApp.newRecurrence()
creates a new Recurrence object, with .addWeeklyRule()
setting the recurrence pattern to weekly, and .onlyOnWeekdays([])
specifying the days of the week to repeat on. The resulting recurrence
object can then be passed to EventRecurrence.setRecurrence(recurrence)
to apply the recurrence pattern to an event.
Once you have a Recurrence object, you can use the following methods to customize the recurrence pattern further:
.addDailyRule()
: Sets the recurrence pattern to repeat every day..addMonthlyRule()
: Sets the recurrence pattern to repeat every month..addYearlyRule()
: Sets the recurrence pattern to repeat every year..onlyOnWeekday(weekday)
: Sets the recurrence to repeat only on a single weekday..onlyOnWeekdays(weekdays)
: Sets the recurrence to repeat only on a list of weekdays..onlyInMonth(month)
: Sets the recurrence to repeat only in a single month (by index)..onlyInMonths(months)
: Sets the recurrence to repeat only in a list of months (by index)..until(endDate)
: Sets a date after which the recurrence should stop..interval(interval)
: Sets the interval at which the recurrence occurs (e.g. every other week)..byMonthDay(day)
: Sets the recurrence to occur only on a specific day of the month..byMonthDays(days)
: Sets the recurrence to occur only on a list of days of the month..bySetPosition(position)
: Sets the recurrence to occur only on a specific instance of a recurrence pattern (e.g. the 2nd Friday of every month).CalendarApp.newRecurrence()
can be used to create a variety of recurrence patterns for calendar events in Google Apps Script. By using the addWeeklyRule()
, addDailyRule()
, addMonthlyRule()
methods, as well as other methods provided by the Recurrence object, you can create complex schedules for repeating events.