3

我在 Google 日历中有几个日历。我正在学习 Google Script,并想创建一个脚本,将事件从我的一个日历复制到另一个日历,并有机会修改诸如重复之类的参数。

4

2 回答 2

2

一些代码开始:

function myFunction() {
  var calendarSource = CalendarApp.getCalendarById("calendarID");
  var calendarDestination = CalendarApp.getCalendarById("calendarID");
  var eventToCopy = calendarSource.getEvents(new Date("July 21, 2009 EST"), new Date("July 22, 2009 EST"));

  //read up: https://developers.google.com/apps-script/class_recurrence
  var newRecurrence = CalendarApp.newRecurrence().addWeeklyRule().times(10);

  for (var i in eventToCopy){
    if (eventToCopy[i].getTitle() == "event name"){
      var newEvent = calendarDestination.createEventSeries(eventToCopy[i].getTitle(), eventToCopy[i].getStartTime(), eventToCopy[i].getEndTime(), newRecurrence);
    }

}

这应该让你开始,

于 2012-09-24T08:43:37.720 回答
2

这是一个旧线程,但这里是如何获取重复字段:

function test_allEventsFromTo() {
  var events = allEventsFromTo("primary", "1 feb 2018", "1 jul 2018");

  //display
  Logger.log("Events #%s\n", events.length);
  for (var i = 0; i < events.length; i++) {
    Logger.log("Title: %s, From: %s, To: %s, recurrence: %s", 
                events[i].summary, events[i].start.dateTime, events[i].end.dateTime, events[i].recurrence);
  }
}


function allEventsFromTo(calendarId, startDate, endDate) { 
  //filter setup
  var optionalArgs = {
    timeMin: (new Date(startDate)).toISOString(),
    timeMax: (new Date(endDate)).toISOString(),
    showDeleted: false,
    singleEvents: false,  //true expands recurring events
  };

  //Filter by calendarId and date range
  var response = Calendar.Events.list(calendarId, optionalArgs);

  return response.items;
}

有关活动的更多信息:

事件、资源表示: https ://developers.google.com/calendar/v3/reference/events

重复字段字符串格式: https ://developers.google.com/calendar/concepts/events-calendars#recurring_events

于 2018-06-09T05:20:01.993 回答