Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • clicking on an instance of the event and saying "copy to my calendar" only copies that single event, even though the event is defined as repeating. This is not a good solution, since the user would have to do this more than 10 times to get all the events for a semester.
  • clicking on an instance of the event and then "More details" , then trying to "Copy to xxxx" under the "More actions" menu (where xxxx is a calendar the user owns) appears to work. However, when clicking Save, there is an error: "An error has occurred. Please try again later."

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 
like image 871
Fuhrmanator Avatar asked Oct 22 '22 18:10

Fuhrmanator


2 Answers

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.

like image 121
Eric Koleda Avatar answered Oct 25 '22 19:10

Eric Koleda


The other option would be to try and export the ICA and have the user import it. You might be even able to do both with some sort of link button. Here is an example of how to obtain the ica file for a google event;

http://google.com/calendar/ical/[CALENDARID]/public[or private depending]/full/[eventID].ics

This should give the code to the user and they can manually import it into their calendars. You can generate the url and send in an email to all students who sign up for the named course.

T

like image 40
Tamer Ziady Avatar answered Oct 25 '22 19:10

Tamer Ziady