【发布时间】:2022-11-16 21:55:34
【问题描述】:
我想知道在谷歌日历中找到一个开放时间段的聪明方法是什么。 目前我正在使用对 Google 日历 API 的 HTTP 请求,特别是 freeBusy 调用。
我需要专门寻找一个 30 分钟的窗口,所以我想到的一种蛮力方法是获取当前时间,检查窗口,然后通过将当前时间增加 5 分钟来遍历当天剩余的时间。不过这看起来很简陋。
这是我必须检查以找到 30 分钟空闲时间块的当前代码:
var date = {
value: "2022-11-15",
};
var startTime = {
value: "22:30",
};
var endTime = {
value: "23:00",
};
var dateObj = {
timeMin: date.value + "T" + startTime.value + ":00-08:00",
timeMax: date.value + "T" + endTime.value + ":00-08:00",
items: [
{
id: calendarId,
},
],
timeZone: "America/Vancouver",
};
console.log(dateObj);
const test = {
method: "POST",
async: true,
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
body: JSON.stringify(dateObj),
};
await fetch(
"https://www.googleapis.com/calendar/v3/freeBusy",
test
)
.then((response) => response.json()) // Transform the data into json
.then((data) => console.log(data))
.catch((err) => console.log(err));
【问题讨论】:
标签: javascript google-chrome-extension google-calendar-api