Google Apps Script

Class Calendar

Represents a calendar that the user owns or is subscribed to.

Methods

MethodReturn typeBrief description
createAllDayEvent(title, date)CalendarEventCreates a new all-day event.
createAllDayEvent(title, date, options)CalendarEventCreates a new all-day event.
createAllDayEventSeries(title, startDate, recurrence)CalendarEventSeriesCreates a new all-day event series.
createAllDayEventSeries(title, startDate, recurrence, options)CalendarEventSeriesCreates a new all-day event series.
createEvent(title, startTime, endTime)CalendarEventCreates a new event.
createEvent(title, startTime, endTime, options)CalendarEventCreates a new event.
createEventFromDescription(description)CalendarEventCreates an event from a free-form description.
createEventSeries(title, startTime, endTime, recurrence)CalendarEventSeriesCreates a new event series.
createEventSeries(title, startTime, endTime, recurrence, options)CalendarEventSeriesCreates a new event series.
deleteCalendar()voidDeletes the calendar permanently.
getColor()StringGets the color of the calendar.
getDescription()StringGets the description of the calendar.
getEventSeriesById(iCalId)CalendarEventSeriesGets the event series with the given ID.
getEvents(startTime, endTime)CalendarEvent[]Gets all events that occur within a given time range.
getEvents(startTime, endTime, options)CalendarEvent[]Gets all events that occur within a given time range and meet the specified criteria.
getEventsForDay(date)CalendarEvent[]Gets all events that occur on a given day.
getEventsForDay(date, options)CalendarEvent[]Gets all events that occur on a given day and meet specified criteria.
getId()StringGets the ID of the calendar.
getName()StringGets the name of the calendar.
getTimeZone()StringGets the time zone of the calendar.
isHidden()BooleanDetermines whether the calendar is hidden in the user interface.
isMyPrimaryCalendar()BooleanDetermines whether the calendar is the default calendar for the effective user.
isOwnedByMe()BooleanDetermines whether the calendar is owned by the effective user.
isSelected()BooleanDetermines whether the calendar's events are displayed in the user interface.
setColor(color)CalendarSets the color of the calendar.
setDescription(description)CalendarSets the description of the calendar.
setHidden(hidden)CalendarSets whether the calendar is visible in the user interface.
setName(name)CalendarSets the name of the calendar.
setSelected(selected)CalendarSets whether the calendar's events are displayed in the user interface.
setTimeZone(timeZone)CalendarSets the time zone of the calendar.
unsubscribeFromCalendar()voidUnsubscribes the user from the calendar.

Detailed documentation

createAllDayEvent(title, date)

Creates a new all-day event.

 
// Creates an all-day event for the moon landing and logs the ID.
 var event = CalendarApp.getDefaultCalendar().createAllDayEvent('Apollo 11 Landing',
     new Date('July 20, 1969'));
 Logger.log('Event ID: ' + event.getId());
 

Parameters

NameTypeDescription
titleStringthe title of the event
dateDatethe date of the event (only the day is used; the time is ignored)

Return

CalendarEvent — the created event


createAllDayEvent(title, date, options)

Creates a new all-day event.

 
// Creates an all-day event for the moon landing and logs the ID.
 var event = CalendarApp.getDefaultCalendar().createAllDayEvent('Apollo 11 Landing',
     new Date('July 20, 1969'),
     {location: 'The Moon'});
 Logger.log('Event ID: ' + event.getId());
 

Parameters

NameTypeDescription
titleStringthe title of the event
dateDatethe date of the event (only the day is used; the time is ignored)
optionsObjecta JavaScript object that specifies advanced parameters, as listed below

Advanced parameters

NameTypeDescription
descriptionStringthe description of the event
locationStringthe location of the event
guestsStringa comma-separated list of email addresses that should be added as guests
sendInvitesBooleanwhether to send invitation emails (default: false)

Return

CalendarEvent — the created event


createAllDayEventSeries(title, startDate, recurrence)

Creates a new all-day event series.

 
// Creates an event series for a no-meetings day, taking place every Wednesday in 2013.
 var eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries('No Meetings',
     new Date('January 2, 2013 03:00:00 PM EST'),
     CalendarApp.newRecurrence().addWeeklyRule()
         .onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY)
         .until(new Date('January 1, 2014')));
 Logger.log('Event Series ID: ' + eventSeries.getId());
 

Parameters

NameTypeDescription
titleStringthe title of the events in the series
startDateDatethe date of the first event in the series (only the day is used; the time is ignored)
recurrenceEventRecurrencethe recurrence settings of the event series

Return

CalendarEventSeries — the created event series


createAllDayEventSeries(title, startDate, recurrence, options)

Creates a new all-day event series.

 
// Creates an event series for a no-meetings day, taking place every Wednesday in 2013.
 var eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries('No Meetings',
     new Date('January 2, 2013 03:00:00 PM EST'),
     CalendarApp.newRecurrence().addWeeklyRule()
         .onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY)
         .until(new Date('January 1, 2014')),
     {guests: 'everyone@example.com'});
 Logger.log('Event Series ID: ' + eventSeries.getId());
 

Parameters

NameTypeDescription
titleStringthe title of the events in the series
startDateDatethe date of the first event in the series (only the day is used; the time is ignored)
recurrenceEventRecurrencethe recurrence settings of the event series
optionsObjecta JavaScript object that specifies advanced parameters, as listed below

Advanced parameters

NameTypeDescription
descriptionStringthe description of the events in the series
locationStringthe location of the events in the series
guestsStringa comma-separated list of email addresses that should be added as guests to the events in the series
sendInvitesBooleanwhether to send invitation emails (default: false)

Return

CalendarEventSeries — the created event series


createEvent(title, startTime, endTime)

Creates a new event.

If no time zone is specified, the time values are interpreted in the context of the script's time zone, which may be different than the calendar's time zone.

 
// Creates an event for the moon landing and logs the ID.
 var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing',
     new Date('July 20, 1969 20:00:00 UTC'),
     new Date('July 21, 1969 21:00:00 UTC'));
 Logger.log('Event ID: ' + event.getId());
 

Parameters

NameTypeDescription
titleStringthe title of the event
startTimeDatethe date and time when the event starts
endTimeDatethe date and time when the event ends

Return

CalendarEvent — the created event


createEvent(title, startTime, endTime, options)

Creates a new event.

If no time zone is specified, the time values are interpreted in the context of the script's time zone, which may be different than the calendar's time zone.

 
// Creates an event for the moon landing and logs the ID.
 var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing',
     new Date('July 20, 1969 20:00:00 UTC'),
     new Date('July 20, 1969 21:00:00 UTC'),
     {location: 'The Moon'});
 Logger.log('Event ID: ' + event.getId());
 

Parameters

NameTypeDescription
titleStringthe title of the event
startTimeDatethe date and time when the event starts
endTimeDatethe date and time when the event ends
optionsObjecta JavaScript object that specifies advanced parameters, as listed below

Advanced parameters

NameTypeDescription
descriptionStringthe description of the event
locationStringthe location of the event
guestsStringa comma-separated list of email addresses that should be added as guests
sendInvitesBooleanwhether to send invitation emails (default: false)

Return

CalendarEvent — the created event


createEventFromDescription(description)

Creates an event from a free-form description.

The description should use the same format as the UI's "Quick Add" feature.

 
// Creates a new event and logs its ID.
 var event = CalendarApp.getDefaultCalendar()
     .createEventFromDescription('Lunch with Mary, Friday at 1PM');
 Logger.log('Event ID: ' + event.getId());
 

Parameters

NameTypeDescription
descriptionStringa free-form description of the event

Return

CalendarEvent — the created event


createEventSeries(title, startTime, endTime, recurrence)

Creates a new event series.

 
// Creates an event series for a team meeting, taking place every Tuesday and Thursday in 2013.
 var eventSeries = CalendarApp.getDefaultCalendar().createEventSeries('Team Meeting',
     new Date('January 1, 2013 03:00:00 PM EST'),
     new Date('January 1, 2013 04:00:00 PM EST'),
     CalendarApp.newRecurrence().addWeeklyRule()
         .onlyOnWeekdays([CalendarApp.Weekday.TUESDAY, CalendarApp.Weekday.THURSDAY])
         .until(new Date('January 1, 2014')));
 Logger.log('Event Series ID: ' + eventSeries.getId());
 

Parameters

NameTypeDescription
titleStringthe title of the events in the series
startTimeDatethe date and time when the first event in the series starts
endTimeDatethe date and time when the first event in the series ends
recurrenceEventRecurrencethe recurrence settings of the event series

Return

CalendarEventSeries — the created event series


createEventSeries(title, startTime, endTime, recurrence, options)

Creates a new event series.

 
// Creates an event series for a team meeting, taking place every Tuesday and Thursday in 2013.
 var eventSeries = CalendarApp.getDefaultCalendar().createEventSeries('Team Meeting',
     new Date('January 1, 2013 03:00:00 PM EST'),
     new Date('January 1, 2013 04:00:00 PM EST'),
     CalendarApp.newRecurrence().addWeeklyRule()
         .onlyOnWeekdays([CalendarApp.Weekday.TUESDAY, CalendarApp.Weekday.THURSDAY])
         .until(new Date('January 1, 2014')),
     {location: 'Conference Room'});
 Logger.log('Event Series ID: ' + eventSeries.getId());
 

Parameters

NameTypeDescription
titleStringthe title of the events in the series
startTimeDatethe date and time when the first event in the series starts
endTimeDatethe date and time when the first event in the series ends
recurrenceEventRecurrencethe recurrence settings of the event series
optionsObjecta JavaScript object that specifies advanced parameters, as listed below

Advanced parameters

NameTypeDescription
descriptionStringthe description of the events in the series
locationStringthe location of the events in the series
guestsStringa comma-separated list of email addresses that should be added as guests to the events in the series
sendInvitesBooleanwhether to send invitation emails (default: false)

Return

CalendarEventSeries — the created event series


deleteCalendar()

Deletes the calendar permanently. A user can only delete a calendar they own.


getColor()

Gets the color of the calendar.

Return

String — a hexadecimal color string ("#rrggbb")


getDescription()

Gets the description of the calendar.

Return

String — the description of this calendar


getEventSeriesById(iCalId)

Gets the event series with the given ID. If the ID given is for a single CalendarEvent, then a CalendarEventSeries will be returned with a single event in the series. Note that if the event series belongs to a calendar other than the default calendar, this method must be called from that Calendar; calling CalendarApp.getEventSeriesById(id) directly will only return an event series that exists in the default calendar.

Parameters

NameTypeDescription
iCalIdStringID of the event series

Return

CalendarEventSeries — the series with the given ID, or null if the series doesn't exist or the user cannot access it


getEvents(startTime, endTime)

Gets all events that occur within a given time range.

An event will be returned if it starts during the time range, ends during the time range, or encompasses the time range. If no time zone is specified, the time values are interpreted in the context of the script's time zone, which may be different from the calendar's time zone.

 
// Determines how many events are happening in the next two hours.
 var now = new Date();
 var twoHoursFromNow = new Date(now.getTime() + (2 * 60 * 60 * 1000));
 var events = CalendarApp.getDefaultCalendar().getEvents(now, twoHoursFromNow);
 Logger.log('Number of events: ' + events.length);
 

Parameters

NameTypeDescription
startTimeDatethe start of the time range
endTimeDatethe end of the time range, non-inclusive

Return

CalendarEvent[] — the events that occur within the time range


getEvents(startTime, endTime, options)

Gets all events that occur within a given time range and meet the specified criteria.

An event will be returned if it starts during the time range, ends during the time range, or encompasses the time range. If no time zone is specified, the time values are interpreted in the context of the script's time zone, which may be different from the calendar's time zone.

Be aware that filtering on author, search, or statusFilters takes place after applying start and max. This means that the number of events returned may be less than max, even though additional events meet the criteria.

 
// Determines how many events are happening in the next two hours that contain the term
 // "meeting".
 var now = new Date();
 var twoHoursFromNow = new Date(now.getTime() + (2 * 60 * 60 * 1000));
 var events = CalendarApp.getDefaultCalendar().getEvents(now, twoHoursFromNow,
     {search: 'meeting'});
 Logger.log('Number of events: ' + events.length);
 

Parameters

NameTypeDescription
startTimeDatethe start of the time range
endTimeDatethe end of the time range, non-inclusive
optionsObjecta JavaScript object that specifies advanced parameters, as listed below

Advanced parameters

NameTypeDescription
startIntegerthe index of the first event to return
maxIntegerthe maximum number of events to return
authorStringan email address used to filter results by the event creator
searchStringa full-text search query used to filter results
statusFilters[]GuestStatusan array of statuses used to filter results

Return

CalendarEvent[] — the events that take place within the time range and match the criteria


getEventsForDay(date)

Gets all events that occur on a given day.

An event will be returned if it starts during the day, ends during the day, or encompasses the day.

Note that only the date portion of the Date object is used, and the time portion is ignored. The date is interpreted as midnight that day to midnight the next day in the calendar's time zone.

 
// Determines how many events are happening today.
 var today = new Date();
 var events = CalendarApp.getDefaultCalendar().getEventsForDay(today);
 Logger.log('Number of events: ' + events.length);
 

Parameters

NameTypeDescription
dateDatethe date to retrieve events for (only the day is used; the time is ignored)

Return

CalendarEvent[] — the events that occur on the given date


getEventsForDay(date, options)

Gets all events that occur on a given day and meet specified criteria.

An event will be returned if it starts during the day, ends during the day, or encompasses the day.

Note that only the date portion of the Date object is used, and the time portion is ignored. The date is interpreted as midnight that day to midnight the next day in the calendar's time zone.

Be aware that filtering on author, search, or statusFilters takes place after applying start and max. This means that the number of events returned may be less than max, even though additional events meet the criteria.

 
// Determines how many events are happening today and contain the term "meeting".
 var today = new Date();
 var events = CalendarApp.getDefaultCalendar().getEventsForDay(today, {search: 'meeting'});
 Logger.log('Number of events: ' + events.length);
 

Parameters

NameTypeDescription
dateDatethe date to retrieve events for (only the day is used; the time is ignored)
optionsObjectadvanced filtering options

Advanced parameters

NameTypeDescription
startIntegerthe index of the first event to return
maxIntegerthe maximum number of events to return
authorStringan email address used to filter results by the event creator
searchStringa full-text search query used to filter results
statusFilters[]GuestStatusan array of statuses used to filter results

Return

CalendarEvent[] — the events that occur on the given date and match the criteria


getId()

Gets the ID of the calendar. The ID for a user's default calendar is their email address.

Return

String — the ID of the calendar


getName()

Gets the name of the calendar.

Return

String — this calendar's name


getTimeZone()

Gets the time zone of the calendar.

Return

String — the time zone, specified in "long" format (e.g., "America/New_York", as listed by Joda.org)


isHidden()

Determines whether the calendar is hidden in the user interface.

Return

Booleantrue if the calendar is hidden in the user interface; false if not


isMyPrimaryCalendar()

Determines whether the calendar is the default calendar for the effective user.

Return

Booleantrue if the calendar is the default calendar for the effective user; false if not


isOwnedByMe()

Determines whether the calendar is owned by the effective user.

Return

Booleantrue if the calendar is owned by the effective user; false if not


isSelected()

Determines whether the calendar's events are displayed in the user interface.

Return

Booleantrue if the calendar's events are displayed in the user interface; false if not


setColor(color)

Sets the color of the calendar.

Parameters

NameTypeDescription
colorStringa hexadecimal color string ("#rrggbb") or a value from CalendarApp.Colors

Return

Calendar — this calendar for chaining


setDescription(description)

Sets the description of the calendar.

Parameters

NameTypeDescription
descriptionStringthe description of this calendar

Return

Calendar — this calendar for chaining


setHidden(hidden)

Sets whether the calendar is visible in the user interface.

Parameters

NameTypeDescription
hiddenBooleantrue to hide the calendar in the user interface; false to show it

Return

Calendar — this calendar for chaining


setName(name)

Sets the name of the calendar.

Parameters

NameTypeDescription
nameStringthe new name

Return

Calendar — this calendar for chaining


setSelected(selected)

Sets whether the calendar's events are displayed in the user interface.

Parameters

NameTypeDescription
selectedBooleantrue to show the calendar's events in the user interface; false to hide them

Return

Calendar — this calendar for chaining


setTimeZone(timeZone)

Sets the time zone of the calendar.

Parameters

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

Return

Calendar — this calendar for chaining


unsubscribeFromCalendar()

Unsubscribes the user from the calendar. A user cannot unsubscribe from a calendar they own.

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.