Google Calendar API全天活动跨越一天?
在我的位于美国/多伦多时区的 Google 日历中,我有一个活动被标记为 2022 年 4 月 13 日全天,但它会以 2022 年 4 月 13 日开始并于 2022 年 4 月结束的方式返回-14。我还有其他一些全天活动也以同样的方式进行。
这发生在我的代码中,而且当我尝试使用此处的 API 测试表单时也会发生这种情况:
https://developers.google.com/calendar/api/v3/reference/events/list
带参数:
- timeMin:
2022-04-10T18:36:39.000Z
- timeMax:
2022-04-17T18:36:39.000Z
这会返回以下响应(某些字段被屏蔽):
"kind": "calendar#events",
"etag": "\"p328ftm5rim7ve0g\"",
"summary": "My Test Calendar",
"updated": "2022-04-12T18:36:40.074Z",
"timeZone": "America/Toronto",
"accessRole": "owner",
"defaultReminders": [],
"nextSyncToken": "xxx-xxxx_cCEJD-2LuVj_cCGAUg8t3t0QE=",
"items": [
{
"kind": "calendar#event",
"etag": "\"3299577200148000\"",
"id": "xxxxga02nqb11ub6dm29dgg9t",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=xxxxxxnYTAybnFiMTF1YjZkbTI5ZGdnOXQgY19uZ2hqOXFzb25tYjRtNDRqN2doaTNxNzY5a0Bn&ctz=UTC",
"created": "2022-04-12T18:36:39.000Z",
"updated": "2022-04-12T18:36:40.074Z",
"summary": "Dummy Event",
"creator": {
"email": "xxxxxx",
"displayName": "xxxxxx"
},
"organizer": {
"email": "[email protected]",
"displayName": "My Test Calendar",
"self": true
},
"start": {
"date": "2022-04-13"
},
"end": {
"date": "2022-04-14"
},
"transparency": "transparent",
"iCalUID": "[email protected]",
"sequence": 0,
"reminders": {
"useDefault": false
},
"eventType": "default"
}
]
}
我尝试过在请求中提供“America/Toronto”和“UTC”作为 timeZone
参数,但这不会改变任何内容。
任何人都可以建议如何让全天活动仅跨越预定发生的日期吗?
顺便说一句,您可以在下面看到该事件仅在一天内发生:
In my Google calendar, which is in the America/Toronto timezone, I have an event that is marked as an all day on the 13 April 2022, but it is coming back as starting on 2022-04-13 and ending on 2022-04-14. I have some other all day event behaving in the same way.
This is happening from my code, but also when I try with the API test form here:
https://developers.google.com/calendar/api/v3/reference/events/list
With parameters:
- timeMin:
2022-04-10T18:36:39.000Z
- timeMax:
2022-04-17T18:36:39.000Z
This returns me the following response (certain fields masked):
"kind": "calendar#events",
"etag": "\"p328ftm5rim7ve0g\"",
"summary": "My Test Calendar",
"updated": "2022-04-12T18:36:40.074Z",
"timeZone": "America/Toronto",
"accessRole": "owner",
"defaultReminders": [],
"nextSyncToken": "xxx-xxxx_cCEJD-2LuVj_cCGAUg8t3t0QE=",
"items": [
{
"kind": "calendar#event",
"etag": "\"3299577200148000\"",
"id": "xxxxga02nqb11ub6dm29dgg9t",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=xxxxxxnYTAybnFiMTF1YjZkbTI5ZGdnOXQgY19uZ2hqOXFzb25tYjRtNDRqN2doaTNxNzY5a0Bn&ctz=UTC",
"created": "2022-04-12T18:36:39.000Z",
"updated": "2022-04-12T18:36:40.074Z",
"summary": "Dummy Event",
"creator": {
"email": "xxxxxx",
"displayName": "xxxxxx"
},
"organizer": {
"email": "[email protected]",
"displayName": "My Test Calendar",
"self": true
},
"start": {
"date": "2022-04-13"
},
"end": {
"date": "2022-04-14"
},
"transparency": "transparent",
"iCalUID": "[email protected]",
"sequence": 0,
"reminders": {
"useDefault": false
},
"eventType": "default"
}
]
}
I tried providing both 'America/Toronto' and 'UTC' as timeZone
parameters in the request, but this does not change anything.
Can anyone suggest how to get an all day event to span only the day it is meant to be happening on?
BTW below you can see the event was only on a single day:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是日历 API 的预期行为。全天活动持续24小时。从开始日期的午夜持续到第二天的午夜。
活动资源中也写有
end
是独占的。另一种解决方案是 -1 响应正文的结束日期或手动绘制时间。但如果您尝试通过绘制时间来手动创建全天事件,它只能持续23.5 小时。
This is an expected behavior from the Calendar API. All day event last for 24 hours. Lasting from midnight of start date to midnight of the next day.
It is also written in the Event Resource that
end
is exclusive.An alternative solution to this is to -1 the end date of the response body or manually plot the time. But if you try to manually create an All day event by plotting the time, It can only last for 23.5 hrs.