您展示的示例适用于全天事件(仅指定第一次发生的日期),您是应用于此类事件还是“正常”事件?
在最后一种情况下,您应该为第一次出现提供 2 个日期(开始和结束)。
上面的链接显示了非常清楚的文档......
这是一个“端到端”示例,展示了它是如何工作的,第一个函数创建一个从今天开始每年重复的事件,第二个函数将这个重复更改为每天,从今天开始......
它使用您的默认日历
function createTestSerie(){
var cal = CalendarApp.getDefaultCalendar()
if (cal) {
var title = 'Test Event';
var desc = 'Created using Google Apps Script';
var loc = 'Here, there and everywhere...';
var recur = CalendarApp.newRecurrence().addYearlyRule().interval(1)
var start = new Date();
var end = new Date(start.valueOf()+3600*1000);
var event = cal.createEventSeries(title, start, end,recur,{description:desc,location:loc});// event will be every year and last 1 hour
}
}
function modifyRecurrence(){
var cal = CalendarApp.getDefaultCalendar()
if (cal) {
var start = new Date();
var end = new Date(start.getTime()+3600*1000*2);
var events = cal.getEvents(new Date("February 16, 2013 08:00:00 PDT"), new Date("February 19, 2013 08:00:00 PDT"))
for(i in events){
if(events[i].getTitle()=='Test Event'){
var recur = CalendarApp.newRecurrence().addDailyRule().interval(1)
var eventId = events[i].getId()
cal.getEventSeriesById(eventId).setRecurrence(recur, start, end);// now events will be lasting 2 hours evey day starting today
}
}
}
}
根据您的评论进行编辑: 它对 allDayEvents 的工作方式完全相同,这是一个修改后的示例代码:
function createAllDaySerie(){
var cal = CalendarApp.getDefaultCalendar()
if (cal) {
var title = 'All Day Test Event';
var start = new Date();
var desc = 'Created using Google Apps Script';
var loc = 'home';
var recur = CalendarApp.newRecurrence().addYearlyRule().interval(4)
var start = new Date();
var event = cal.createAllDayEventSeries(title, start,recur,{description:desc,location:loc});// event will be every 4 years starting today
}
}
function modifyAllDayRecurrence(){
var cal = CalendarApp.getDefaultCalendar()
if (cal) {
var start = new Date("February 19, 2010 08:00:00 PDT");// here you can choose any date you like that will be the new start date.
var events = cal.getEvents(new Date("February 16, 2013 08:00:00 PDT"), new Date("February 22, 2013 08:00:00 PDT"))
for(i in events){
if(events[i].getTitle()=='All Day Test Event'){
var recur = CalendarApp.newRecurrence().addYearlyRule().interval(1)
var eventId = events[i].getId()
cal.getEventSeriesById(eventId).setRecurrence(recur, start);// now events will occur once a year starting on february 19, 2010 (see screen capture below)
}
}
}
}