A builder for clock triggers
Methods
Method | Return type | Brief description |
---|---|---|
after(durationMilliseconds) | ClockTriggerBuilder | Specifies the duration (in milliseconds) after the current time that the trigger will run. |
at(date) | ClockTriggerBuilder | Specifies when the trigger will run (plus or minus 15 minutes). |
atDate(year, month, day) | ClockTriggerBuilder | Specifies trigger will fire on the given date, by default near midnight (+/- 15 minutes). |
atHour(hour) | ClockTriggerBuilder | Specifies the hour the trigger will run (plus or minus 15 minutes). |
create() | Trigger | Creates the trigger. |
everyDays(n) | ClockTriggerBuilder | Specifies to run the trigger every n days. |
everyHours(n) | ClockTriggerBuilder | Specifies to run the trigger every n hours. |
everyMinutes(n) | ClockTriggerBuilder | Specifies to run the trigger every n minutes. |
everyWeeks(n) | ClockTriggerBuilder | Specifies to run the trigger every n weeks. |
inTimezone(timezone) | ClockTriggerBuilder | Specifies the timezone that the specified dates/time that the trigger will run in. |
nearMinute(minute) | ClockTriggerBuilder | Specifies the minute the trigger will run (plus or minus 15 minutes). |
onMonthDay(day) | ClockTriggerBuilder | Specifies on what date in the month that the trigger will run. |
onWeekDay(day) | ClockTriggerBuilder | Specifies on what day of the week that the trigger will run. |
Detailed documentation
after(durationMilliseconds)
Specifies the duration (in milliseconds) after the current time that the trigger will run. (plus or minus 15 minutes).
// Creates a trigger that will run 10 minutes later
ScriptApp.newTrigger("myFunction")
.timeBased()
.after(10 * 60 * 1000)
.create();
Parameters
Name | Type | Description |
---|---|---|
durationMilliseconds | Integer | the duration (in milliseconds) after the current time when the trigger should run |
Return
ClockTriggerBuilder
— the builder for chaining
at(date)
Specifies when the trigger will run (plus or minus 15 minutes).
// Creates a trigger for December 1, 2012
var triggerDay = new Date(2012, 11, 1);
ScriptApp.newTrigger("myFunction")
.timeBased()
.at(triggerDay)
.create();
Parameters
Name | Type | Description |
---|---|---|
date | Date | a Date object representing when the trigger should run |
Return
ClockTriggerBuilder
— the builder for chaining
atDate(year, month, day)
Specifies trigger will fire on the given date, by default near midnight (+/- 15 minutes).
// Schedules for January 1st, 2013
ScriptApp.newTrigger("myFunction")
.timeBased()
.atDate(2013, 1, 1)
.create();
Parameters
Name | Type | Description |
---|---|---|
year | Integer | the calendar year to schedule the trigger |
month | Integer | the calendar month to schedule the trigger (should be a number between 1 and 12, inclusive) |
day | Integer | the calendar day to schedule the trigger (should be a number between 1 and 31, inclusive) |
Return
ClockTriggerBuilder
— the builder for chaining
atHour(hour)
Specifies the hour the trigger will run (plus or minus 15 minutes).
// Runs at 5am in the timezone of the script
ScriptApp.newTrigger("myFunction")
.timeBased()
.atHour(5)
.everyDays(1) // Frequency is required if you are using atHour() or nearMinute()
.create();
Parameters
Name | Type | Description |
---|---|---|
hour | Integer | the hour at which to fire |
Return
ClockTriggerBuilder
— the builder for chaining
everyDays(n)
Specifies to run the trigger every n
days.
ScriptApp.newTrigger("myFunction")
.timeBased()
.everyDays(3)
.create();
Parameters
Name | Type | Description |
---|---|---|
n | Integer | the number of days between executions |
Return
ClockTriggerBuilder
— the builder for chaining
everyHours(n)
Specifies to run the trigger every n
hours.
ScriptApp.newTrigger("myFunction")
.timeBased()
.everyHours(12)
.create();
Parameters
Name | Type | Description |
---|---|---|
n | Integer | the number of hours between executions |
Return
ClockTriggerBuilder
— the builder for chaining
everyMinutes(n)
Specifies to run the trigger every n
minutes. n
must be 1, 5, 10, 15 or 30.
ScriptApp.newTrigger("myFunction")
.timeBased()
.everyMinutes(10)
.create();
Parameters
Name | Type | Description |
---|---|---|
n | Integer | the number of minutes between executions |
Return
ClockTriggerBuilder
— the builder for chaining
everyWeeks(n)
Specifies to run the trigger every n
weeks.
ScriptApp.newTrigger("myFunction")
.timeBased()
.everyWeeks(2)
.create();
Parameters
Name | Type | Description |
---|---|---|
n | Integer | the number of weeks between executions |
Return
ClockTriggerBuilder
— the builder for chaining
inTimezone(timezone)
Specifies the timezone that the specified dates/time that the trigger will run in. By
default, the timezone will be that of the script.
The list of valid timezone strings corresponds with the valid timezone strings
for TimeZone
. An invalid timezone string will cause the script
to throw an error.
// Schedule the trigger to execute at noon every day in the US/Pacific time zone
ScriptApp.newTrigger("myFunction")
.timeBased()
.atHour(12)
.everyDays(1)
.inTimezone("America/Los_Angeles")
.create();
Parameters
Name | Type | Description |
---|---|---|
timezone | String | the timezone with which to treat time information in the event |
Return
See also
-
TimeZone
nearMinute(minute)
Specifies the minute the trigger will run (plus or minus 15 minutes).
// Runs at approximately 5:30am in the timezone of the script
ScriptApp.newTrigger("myFunction")
.timeBased()
.atHour(5)
.nearMinute(30)
.everyDays(1) // Frequency is required if you are using atHour() or nearMinute()
.create();
Parameters
Name | Type | Description |
---|---|---|
minute | Integer | the minute at which to fire |
Return
ClockTriggerBuilder
— the builder for chaining
onMonthDay(day)
Specifies on what date in the month that the trigger will run.
// Schedules for the first of every month
ScriptApp.newTrigger("myFunction")
.timeBased()
.onMonthDay(1)
.create();
Parameters
Name | Type | Description |
---|---|---|
day | Integer | the day of the month the trigger should be scheduled for |
Return
ClockTriggerBuilder
— the builder for chaining
onWeekDay(day)
Specifies on what day of the week that the trigger will run.
ScriptApp.newTrigger("myFunction")
.timeBased()
.onWeekDay(ScriptApp.WeekDay.FRIDAY)
.create();
Parameters
Name | Type | Description |
---|---|---|
day | Weekday | the day of the week to fire |
Return
ClockTriggerBuilder
— the builder for chaining