google-apps-scriptgoogle-calendar-apigoogle-calendar-recurring-events

Copy a programmatically created recurring event?


Using Google Apps Script, I created a calendar that has a complex recurring event. However, I'm not able to copy that event to another calendar as a recurring event. Note: the recurring rule can't be generated or edited via the web interface.

For a real example, let's say a user wants to copy the recurring event from this publicly shared Google calendar. The event is a kind of template event for a course schedule of a Thursday course at my university.

Here are two difficulties preventing the user from copying the recurring event into another calendar the user has access to:

EDIT here's a screen shot of what the Event looks like in Google Calendar (click on event, "more details").

screen shot of details of the created event

Note that this recurring event is every Monday from the start of the semester to the end, with several exceptions. No holidays (e.g., Mon 2013-02-25), but also including Wed 2013-02-27, on which day the courses will be given as if it were a Monday (according to the university course schedule).

I repeat: the recurring events look fine in Google Calendar, but they can't be copied in there entirety to another calendar.

The GAS function that creates the calendars (not all the code is here):

function createCalendar(calendarName, courseCode, weekday, times, room, isLab) {

  Logger.log("Last day: " + LAST_TRIMESTER_DATE);
  // hack the last day so that it's not midnight but rather just before the next day, i.e., 23:59:59
  var adjustedLastDay = LAST_TRIMESTER_DATE;
  adjustedLastDay.setTime(adjustedLastDay.getTime() + (23*60*60*1000) + (59*60*1000) + (59*1000));
  Logger.log("Adjusted last day: " + adjustedLastDay);

  var eventRecurrence = CalendarApp.newRecurrence();
  eventRecurrence.addDailyRule().until(adjustedLastDay).interval(1).onlyOnWeekday(weekday);

  // get the day of the week of the first day
  var weekdayOfFirstDay = Utilities.formatDate(FIRST_TRIMESTER_DATE, LONG_TIME_ZONE, "EEEE").toUpperCase();

  // if this calendar is for a lab, exclude the first week of days
  if (isLab) {
    eventRecurrence.addDailyExclusion().times(1);
  } else {
    // it's a course, so exclude the first day if it's not the course day
    //  -- this is kind of a bug, since the "first day" of the event will always try to be created, even if it's not "onlyOnWeekday" specified
    if (weekdayOfFirstDay != weekday.toString()) {
      eventRecurrence.addDailyExclusion().times(1);
//    eventRecurrence.addDateExclusion(FIRST_TRIMESTER_DATE);
    }
  }

  // Exclude all holidays
  for (var i =  0; i 

Solution

  • This appears to be a bug in Google Calendar, in that it has trouble copying complex recurrence rules. You can report it to the team by using the "Send feedback" link under the gear icon in the Google Calendar interface.