Monday, March 9, 2015
Google Apps Script and Recurring Calendar Events
The following code snippet creates a calendar event for all days that are Friday the 13th, so you can remember to avoid bad luck on those days.
var calendar = CalendarApp.getCalendarsByName("My Calendar")[0];
var fridayTheThirteenth = CalendarApp.newRecurrence();
fridayTheThirteenth.addDateExclusion(newDate())
.addDailyRule()
.onlyOnWeekday(CalendarApp.Weekday.FRIDAY)
.onlyOnMonthDay(13);
calendar.createAllDayEventSeries("Bad luck!", new Date(),
fridayTheThirteenth)
The next code snippet adds an event to your calendar to remind you of election day in the United States.
var calendar = CalendarApp.getCalendarsByName("My Calendar")[0];
var usaElectionDay = CalendarApp.newRecurrence();
usaElectionDay.addDateExclusion(newDate())
.addYearlyRule().interval(4)
.onlyInMonth(CalendarApp.Month.NOVEMBER)
.onlyOnWeekday(CalendarApp.Weekday.TUESDAY)
.onlyOnMonthDays([2, 3, 4, 5, 6, 7, 8]);
calendar.createAllDayEventSeries("Go vote!!!", new Date(),
usaElectionDay);
The interface to interact with recurring events is very straight forward and powerful. We were able to easily select all days matching the parameters Friday the 13th, and also to match all Tuesdays in each occurrence of November having a date between 2 and 8. You can quickly and easily describe dates and times of recurring events you’re looking for. For more information, please check out the release notes and updated documentation.
Posted by Vic Fryzel, Apps Script Team
Want to weigh in on this topic? Discuss on Buzz
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.