仅在 Google 应用脚本假期日历中添加全天 OOO 事件

问题描述 投票:0回答:1

我正在尝试使用假期日历应用程序脚本,但我只想包含全天事件,无论人们使用的是默认事件还是 OOO 事件。这里有一个类似的问题:Ignore not All-Day events in the Google App Script Vacation Calendar但此答案仅适用于默认事件,并且所有 OOO 类型事件都被过滤掉

此类事件总是会返回并非全天,即使是: Calendar Event

Calendar.Events.list() 返回的 Event 类似乎不包含此信息,但根据我更改的另一个线程以检索 CalendarEvent 对象,并且如果日历事件是默认事件类型,则它可以正常工作。但是,如果该事件是 outOfOffice 事件,那么即使是这样,所有内容都会全天返回为 not,这意味着我的 OOO 事件都不会被添加。有谁知道如何让它正确读取全天与定时的 OOO 事件?

相关代码是这个

shouldImportEvent
函数:

function shouldImportEvent(user, keyword, event) {
  // Filters out events where the keyword did not appear in the summary
  // (that is, the keyword appeared in a different field, and are thus
  // is not likely to be relevant).
  if (event.summary.toLowerCase().indexOf(keyword) < 0) {
    return false;
  }

  // Only import events that are all day
  let calEvent = CalendarApp.getCalendarById(user.getEmail()).getEventById(event.id)
  if (!calEvent.isAllDayEvent()) {
    // all outOfOffice events are returning here
    return false; 
  }

  if (!event.organizer || event.organizer.email == user.getEmail()) {
    // If the user is the creator of the event, always imports it.
    return true;
  }
  // Only imports events the user has accepted.
  if (!event.attendees) return false;
  let matching = event.attendees.filter(function(attendee) {
    return attendee.self;
  });
  return matching.length > 0 && matching[0].responseStatus == 'accepted';
}
javascript google-apps-script google-calendar-api
1个回答
0
投票

不如我希望的那么干净,但我最终使用了开始和结束时间并检查了持续时间,效果很好:

// Only import events that are all day
let calEvent = CalendarApp.getCalendarById(user.getEmail()).getEventById(event.id);
let durationHours = (calEvent.getEndTime() - calEvent.getStartTime()) / 1000 / 60 / 60; 

if (durationHours < 7) {
  return false;
}
© www.soinside.com 2019 - 2024. All rights reserved.