为什么谷歌日历API返回timeZone=UTC,尽管它不正确?



我们的大多数客户是美国人,但在将他们的谷歌日历与我们的服务连接后,我们读取timeZone=UTC:

https://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=owner&access_token=<ACCSES TOKEN>

反应:

{
"kind": "calendar#calendarList",
"etag": ""1407366566837000"",
"nextSyncToken": "00001407366566837000",
"items": [
    {
        "kind": "calendar#calendarListEntry",
        "etag": ""1407184723757000"",
        "id": "sampleemail@gmail.com",
        "summary": "sampleemail@gmail.com",
        "timeZone": "UTC",
        "colorId": "17",
        "backgroundColor": "#9a9cff",
        "foregroundColor": "#000000",
        "selected": true,
        "accessRole": "owner",
        "defaultReminders": [
            {
                "method": "popup",
                "minutes": 30
            }
        ],
        "notificationSettings": {
            "notifications": [
                {
                    "type": "eventCreation",
                    "method": "email"
                },
                {
                    "type": "eventChange",
                    "method": "email"
                },
                {
                    "type": "eventCancellation",
                    "method": "email"
                },
                {
                    "type": "eventResponse",
                    "method": "email"
                }
            ]
        },
        "primary": true
    }
]

}

这种情况发生在很多用户身上,我们很确定他们的日历实际上没有设置为UTC,但Google始终返回UTC。有人熟悉这个问题吗?

https://support.google.com/calendar/answer/2367918?hl=en

日历如何处理时区

无论何时创建事件,Calendar都会将其从您的时区进行转换到UTC时间,使用当前已知的转换规则。通过使用一个所有事件的通用时间,日历可以保留所有客人的无论在哪个时区,日历都是一致的。当我们在日历上显示事件,它从UTC转换为出现在你自己的时区

后端ruby代码:

time_zone = 'Europe/Moscow'
task_time_start_utc = task.date_time
task_time_start_moscow = task_time_start_utc.in_time_zone(time_zone)
task_time_end_utc = task_time_start_utc + task.duration.minutes
task_time_end_moscow = task_time_end_utc.in_time_zone(time_zone)
event_property = {
    summary: task.name,
    location: "#{task.lat} #{task.lng}",
    description: string_work_times,
    start: {
        date_time: task_time_start_moscow.to_formatted_s(:iso8601),
        time_zone: time_zone
    },
    end: {
        date_time: task_time_end_moscow.to_formatted_s(:iso8601),
        time_zone: time_zone
    }
}

相关内容

  • 没有找到相关文章

最新更新