如何修改事件系列的特定实例 [英] How to modify a specific instance of an event series
问题描述
让我们假设我创建一个周期性事件,从星期一上午9点开始,结束于上午11点,此事件每天重复3天。
现在我想(在我使用重复创建事件后)在周二更改事件的开始时间,而其他事件保持不变,我该怎么办?
我可以使用高级日历API轻松获得此事件的循环规则,它会返回类似
RRULE: FREQ = DAILY; COUNT = 3
此规则可随意修改以更改所有事件我也可以使用 patch
更新事件,但不只是一个事件
我尝试了
使用 CalendarApp
,只需指定日期范围,并循环遍历结果,然后使用 .setTime()
:
var cal = CalendarApp.getCalendarsByName('< YOUR_CAL>')[0];
var events = cal.getEvents(new Date(April 5,2016 08:00:00 AM),new Date(April 5,2016 11:30:00 AM));
events.forEach(function(e){
// var e = events [0];
// if(e.getTitle()==='Your Title')
e.setTime(new Date(April 5,2016 11:00:00 AM),new Date(April 5,2016 01:00:00 PM));
});
我不知道你的具体实例是指一个事件还是每个星期二事件,或者您是否有理由在这种情况下甚至使用高级日历API。
Let's suppose I create a recurring event that starts on Monday at 9 AM and ends at 11 AM, this event repeats every day for 3 days. Now I want (after I have created the events using recurrence) to change the start time of the event on Tuesday while leaving the other events unchanged, how could I do ?
I can easily get the recurrence rule for this eventSeries using the advanced calendar API, it returns something like
RRULE:FREQ=DAILY;COUNT=3
This rule can be modified at will to change all the events (and I can also update the events using patch
but not just for a single event.
I tried the API tryout to get every instance of this eventSeries and I can indeed see every start and end times (*see below) but I didn't find any method to get that using the Calendar API in Google Apps Script.
I didn't find a way to modify a particular instance, i.e. to write back the modified values.
Since I can do this manually in the calendar web UI I guess I should be able to do it using a script but I really don't know how.
The code I use to get the event parameters is fairly simple :
...
for(var n = 1 ; n < data.length ; n++){
if(data[n][9] == ''){continue};
var advancedID = data[n][9].substring(0,data[n][9].indexOf('@'));
Logger.log(advancedID+'\n');
ChangeEventRecurrence(calID,advancedID);
}
}
function ChangeEventRecurrence(calID,advancedID){
var event = Calendar.Events.get(calID, advancedID);
Logger.log(event.recurrence+'\n'+JSON.stringify(event));
// here I should be able to get all the instances of this eventSeries and change them if needed
}
Here is a capture of an instance I get using the API tryout :
With CalendarApp
, just specify the date range to look for the single event and loop through the result to then use .setTime()
:
var cal = CalendarApp.getCalendarsByName('<YOUR_CAL>')[0];
var events = cal.getEvents(new Date("April 5, 2016 08:00:00 AM"), new Date("April 5, 2016 11:30:00 AM"));
events.forEach( function(e) {
//var e = events[0];
//if ( e.getTitle() === 'Your Title' )
e.setTime(new Date("April 5, 2016 11:00:00 AM"), new Date("April 5, 2016 01:00:00 PM"));
});
I can't tell if your "specific instance" means just a single event or every Tuesday event though, or whether you have a reason to even use the Advanced Calendar API for this case.
这篇关于如何修改事件系列的特定实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!