Google Apps脚本:日历服务:在CalendarEventSeries中查找第一个事件 [英] Google Apps Script: Calendar Service: Find first event in CalendarEventSeries

查看:61
本文介绍了Google Apps脚本:日历服务:在CalendarEventSeries中查找第一个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算一个人的年龄,这个人的生日作为日历中的事件系列存在.为此,我需要知道本系列中的第一个事件,这就是问题:如何从实际事件中获得系列中的第一个事件?

I'd like to calculate the age of a person whose birthday exists as event series within my calendar. To do this I need to know the first event within this series and that's the question: how to get the first event of a series from an actual event?

谢谢 罗尼

推荐答案

另一个答案实际上并未回答初始请求,CalendarApp没有方法来获取重复事件的开始日期. 您应该使用高级Calendar API(必须手动启用,请参见下文并按照说明进行操作)

The other answer doesn't actually answer the initial request, the CalendarApp has no method to get the start date of a recurring event. You should use the advanced Calendar API (must be enabled manually, see below and follow instructions)

然后使用高级API获取所需的信息(自动完成功能也适用于这些方法,因此您可以轻松查看可用的信息)

Then use the advanced API to get the information you want, (the auto complete feature works on these methods too so you can easily see what is available)

下面的测试代码,请注意,高级日历API的事件ID是不同的,您必须删除'@'之后的部分.

Test code below, note that event ID is different for the advanced Calendar API, you have to remove the part after '@'.

function createTestEvents() {
  var recurrence = CalendarApp.newRecurrence().addWeeklyRule().times(10);
  var testEvent = CalendarApp.getDefaultCalendar().createEventSeries('test event serie', new Date('2016/05/10'), new Date(new Date('2016/05/10').getTime()+12*3600000), recurrence);
  var id = testEvent.getId();
  Logger.log('Event Series ID: ' + id);
  viewTestEvent(id)
}

function viewTestEvent(id){
  var event= CalendarApp.getDefaultCalendar().getEventSeriesById(id);
  var calId = CalendarApp.getDefaultCalendar().getId();
  Logger.log('event title = '+event.getTitle());
  var AdvanncedId = id.substring(0,id.indexOf('@'));
  Logger.log('AdvanncedId = '+AdvanncedId);
  var testEvent = Calendar.Events.get(calId, AdvanncedId);
  Logger.log('testEvent start = '+ testEvent.start);
  return testEvent;
}

function test(){ // a few examples of what you can retrieve...
  var event = viewTestEvent('59buf7nq6nr6qo79bh14kmsr6g@google.com');
  Logger.log('\n\nstart = '+event.start);
  Logger.log('\n\ncreated on = '+event.created);
  Logger.log('\n\nend on = '+event.end);
  Logger.log('\n\nrecurrence = '+event.recurrence);
}

这篇关于Google Apps脚本:日历服务:在CalendarEventSeries中查找第一个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆