复制以编程方式创建的定期事件?

时间:2012-12-19 20:05:08

标签: google-apps-script google-calendar-api google-calendar-recurring-events

使用Google Apps脚本,我创建了一个包含复杂重复活动的日历。但是,我无法将该事件复制到另一个日历作为重复发生的事件。 注意:无法通过Web界面生成或编辑重复规则。

对于一个真实的例子,假设用户想要从this publicly shared Google calendar复制定期事件。该活动是一种模板活动,用于我所在大学周四课程的课程安排。

以下两个难以阻止用户将定期事件复制到用户有权访问的另一个日历中:

  • 单击事件实例并说“复制到我的日历”仅复制该单个事件,即使该事件被定义为重复。这不是一个好的解决方案,因为用户必须执行此操作超过10次才能获得一个学期的所有事件。
  • 点击事件的实例,然后点击“更多详细信息”,然后尝试“更多操作”菜单下的“复制到xxxx”(其中xxxx是用户拥有的日历)似乎可以正常工作。但是,单击“保存”时会出现错误:“发生错误。请稍后再试。”

编辑以下是Google日历中事件的截图(点击事件,“更多详情”)。

screen shot of details of the created event

请注意,这个定期事件是从学期开始到结束的每个星期一,有几个例外。没有假期(例如 Mon 2013-02-25 ),但也包括 2013年3月27日星期三,在哪一天课程将被给予,就像它是一个星期一(根据大学课程安排)。

我再说一遍:重复活动在Google日历中看起来不错,但不能将它们全部复制到另一个日历中。

创建日历的GAS功能(不是所有代码都在这里):

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 

2 个答案:

答案 0 :(得分:2)

这似乎是Google日历中的一个错误,因为它无法复制复杂的重复规则。您可以使用Google日历界面中齿轮图标下的“发送反馈”链接向团队报告。

答案 1 :(得分:1)

另一种选择是尝试导出ICA并让用户导入它。您甚至可以使用某种链接按钮来执行这两项操作。以下是如何获取Google事件的ica文件的示例;

http://google.com/calendar/ical/[CALENDARID]/public[or私人依赖] /完整/ [eventID] .i​​cs

这应该将代码提供给用户,他们可以手动将代码导入到他们的日历中。您可以生成网址并发送电子邮件给所有注册指定课程的学生。

Ť

相关问题