为什么Google Calendar API会返回timeZone = UTC,尽管它不正确?

时间:2014-08-07 09:46:30

标签: google-api google-calendar-api

我们的大多数客户都是美国客户,但在将谷歌日历与我们的服务相关联后,我们会读取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。 有谁熟悉这个问题?

1 个答案:

答案 0 :(得分:0)

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

  

日历如何处理时区

     

每当您创建活动时,日历都会从您的时区转换它   到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
    }
}