In Google's example for createEventSeries (shown below), the Date values are specified with "EST" at the end. However, I want to specify dates for a recurring event (see type #4 of the kinds of times in this answer), e.g., "every Monday at 9pm, even when DST changes." Let's say I can figure out which day is the first Monday of my recurring event. The problem is how do I specify that 9pm of that day should take into consideration whether DST is in force?
It would be intuitive to specify a Date using a time zone name (Olson ID), e.g., using the date from the example, "July 21, 2010 09:00:00 America/Montreal". The resulting Date has a bogus value in 1969 if I try it in Google Apps Script.
How can I specify a new Date()
in Google Apps Script such that it groks the Olson ID I specify, e.g., "America/Montreal" as opposed to me knowing a priori if the date is actually "EST" or "EDT"?
// The code below will add an event to the user's default Calendar that recurs every other day var cal = CalendarApp.getDefaultCalendar(); cal.createEvent("Busy", new Date("July 21, 2010 08:00:00 EST"), new Date("July 21, 2010 09:00:00 EST"), CalendarApp.newRecurrence().addDailyRule().interval(2), {location:'Nap room'});`
p.s. I found a workaround/hack that relies on the information that JavaScript new Date() in GAS will inherit the timezone of the script (see the 4th bullet point). I can set my script's timezone to that of the one I want to create my recurring events, and it appears to work. But I'd like to not rely on this detail, as it seems fragile.
Edit
Here's the output of a small test using the workaround to show you how it works. Note how the GMT-0500 (EST) changes to GMT-0400 (EDT).
function shortTest() { // DST begins on Mar 10, 2012 in "America/Montreal" (Olson ID) // This script's Project Properties show a Time zone (today, Dec 18, 2012) of // "(GMT-05:00) Eastern Time - Montreal" Logger.log("Date = " + (new Date("March 9, 2013 21:00:00"))); Logger.log("Date = " + (new Date("March 10, 2013 21:00:00"))); Logger.log("Date = " + (new Date("March 11, 2013 21:00:00"))); }
Logger output
Date = Sat Mar 09 2013 21:00:00 GMT-0500 (EST) Date = Sun Mar 10 2013 21:00:00 GMT-0400 (EDT) Date = Mon Mar 11 2013 21:00:00 GMT-0400 (EDT)