gpt4 book ai didi

php - Google Calendar API Timezone 日光和标准时间问题

转载 作者:行者123 更新时间:2023-12-04 09:10:20 24 4
gpt4 key购买 nike

当我创建一个事件给它一个近期的日期时,一切正常。
但是,当我在几个月后创建一个事件时,假设它在夏令时 DST 之外(而我目前处于夏令时期间),则创建的事件有一个不需要的 1 小时偏移。
下面的代码导致以下输出:Starts 2020-12-20 9:00 Ends 2020-12-20 11:00

 $event = array(
'summary' => $attributes['summary'],
'location' => $attributes['location'],
'description' => $attributes['description'],
'start' => array(
'dateTime' => 2020-12-20T10:10:00-04:00',
'timeZone' => 'America/Toronto',
),
'end' => array(
'dateTime' => 2020-12-20T10:12:00-04:00',
'timeZone' => 'America/Toronto',
),
'anyoneCanAddSelf'=>true,
'guestsCanInviteOthers'=>true,
);
问题
我应该如何更改我的代码使其自动工作,这样我就不需要每年两次手动更改我的代码/偏移量?

最佳答案

问题是您过度指定了 dateTime参数以包含偏移量,但您还提供了 timeZone范围。在这种情况下,timeZone参数与 dateTime 中的偏移值冲突(美国/多伦多在该日期偏移 -05:00)。
鉴于两者之间的冲突 - 它选择使用 dateTime 中指定的偏移量.
documentation for the Event resource指定,在 end.dateTime 中属性:

The time, as a combined date-time value (formatted according to RFC3339). A time zone offset is required unless a time zone is explicitly specified in timeZone.


(强调)
解决问题的最简单方法是从 dateTime 中删除偏移值。您指定并依赖于 timeZone环境。

关于php - Google Calendar API Timezone 日光和标准时间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63359818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com