A builder for clock triggers.
Methods
Method | Return type | Brief description |
---|---|---|
Clock
|
Specifies the minimum duration (in milliseconds) after the current time that the trigger runs. | |
Clock
|
Specifies when the trigger runs. | |
Clock
|
Specifies that the trigger fires on the given date, by default near midnight (+/- 15 minutes). | |
Clock
|
Specifies the hour the trigger at which the trigger runs. | |
Trigger
|
Creates the trigger. | |
Clock
|
Specifies to run the trigger every n
days. |
|
Clock
|
Specifies to run the trigger every n
hours. |
|
Clock
|
Specifies to run the trigger every n
minutes. |
|
Clock
|
Specifies to run the trigger every n
weeks. |
|
Clock
|
Specifies the timezone for the specified dates/time when the trigger runs. | |
Clock
|
Specifies the minute at which the trigger runs (plus or minus 15 minutes). | |
Clock
|
Specifies the date in the month that the trigger runs. | |
Clock
|
Specifies the day of the week that the trigger runs. |
Detailed documentation
after(durationMilliseconds)
Specifies the minimum duration (in milliseconds) after the current time that the trigger runs. The actual duration might vary, but won't be less than your specified minimum.
// Creates a trigger that runs 10 minutes later ScriptApp . newTrigger ( 'myFunction' ). timeBased (). after ( 10 * 60 * 1000 ). create ();
Parameters
Name | Type | Description |
---|---|---|
duration
|
Integer
|
The minimum duration (in milliseconds) after the current time when the trigger should run. |
Return
Clock
— The builder, for chaining.
at(date)
Specifies when the trigger runs.
// Creates a trigger for December 1, 2012 const 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
Clock
— The builder, for chaining.
at
Date(year, month, day)
Specifies that the trigger fires 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
Clock
— The builder, for chaining.
at
Hour(hour)
Specifies the hour the trigger at which the trigger runs.
// Runs between 5am-6am 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
Clock
— The builder, for chaining.
create()
every
Days(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
Clock
— The builder, for chaining.
every
Hours(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
Clock
— The builder, for chaining.
every
Minutes(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
Clock
— The builder, for chaining.
every
Weeks(n)
Specifies to run the trigger every n
weeks.
ScriptApp . newTrigger ( 'myFunction' ) . timeBased () . everyWeeks ( 2 ) . onWeekDay ( ScriptApp . WeekDay . FRIDAY ) . create ();
Parameters
Name | Type | Description |
---|---|---|
n
|
Integer
|
The number of weeks between executions. |
Return
Clock
— The builder, for chaining.
in
Timezone(timezone)
Specifies the timezone for the specified dates/time when the trigger runs. By default, the timezone is that of the script.
The list of valid timezone strings corresponds with the valid timezone strings listed by Joda.org . An invalid timezone string causes 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
Clock
— This Clock
, for chaining.
near
Minute(minute)
Specifies the minute at which the trigger runs (plus or minus 15 minutes). If near
is not called, a random minute value is used.
// 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
Clock
— The builder, for chaining.
on
Month
Day(day)
Specifies the date in the month that the trigger runs.
// 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
Clock
— The builder, for chaining.
on
Week
Day(day)
Specifies the day of the week that the trigger runs.
ScriptApp . newTrigger ( 'myFunction' ) . timeBased () . onWeekDay ( ScriptApp . WeekDay . FRIDAY ) . create ();
Parameters
Name | Type | Description |
---|---|---|
day
|
Weekday
|
The day of the week to fire. |
Return
Clock
— The builder, for chaining.