Podio:设置 DateTime 字段值时使用哪个时区

Podio: which TimeZone is used while setting DateTime field value

使用跑道创建新项目或更新现有项目时 API,并将 DateTime 字段值设置为:2016-10-21 14:15:00(例如)。将使用哪个时区来存储此日期时间?

例如请求:

app_id = <some app with title and date fields>
content = {'title' => 'Date set to "14:15"',
           'date'  => {'start' => '2016-10-21 14:15:00', 
                       'end'   => '2016-10-21 15:00:00'}}
item = Podio::Item.create(app_id, 'fields' => content)

结果:

'start_date_utc' => 2016-10-21
'end'            => 2016-10-21 15:00:00
'end_date'       => 2016-10-21
'end_date_utc'   => 2016-10-21
'start_time_utc' => 12:15:00
'start_time'     => 14:15:00
'start_date'     => 2016-10-21
'start'          => 2016-10-21 14:15:00
'end_time'       => 15:00:00
'end_time_utc'   => 13:00:00
'end_utc'        => 2016-10-21 13:00:00
'start_utc'      => 2016-10-21 12:15:00

太棒了,因为我看到的时间值 14:15 与我设置的 14:15 相同,但我如何控制和设置特定的 时区 [=26] =] 添加到此 DateTime 字段?

看来跑道 API 很聪明,知道我的时区。

这里有几个请求和结果的例子。 将 DateTime 字段设置为 14:15:00 作为不同的用户和应用进行身份验证。

content = {'date' => {'start' => '2016-10-21 14:15:00'}}
Podio.client.authenticate_with_credentials(<user A>, <pass>)
item_created_by_userA = Podio::Item.create(app_id, 'fields' => content)

Podio.client.authenticate_with_credentials(<user B>, <pass>)
item_created_by_userB = Podio::Item.create(app_id, 'fields' => content)

Podio.client.authenticate_with_app(<app ID>, <app token>)
item_created_by_app = Podio::Item.create(app_id, 'fields' => content)

那么设置的值是:

item_created_by_userA:
'start'     => 2016-10-21 14:15:00
'start_utc' => 2016-10-21 12:15:00

item_created_by_userB:
'start'     => 2016-10-21 14:15:00
'start_utc' => 2016-10-21 21:15:00

item_created_by_app:
'start'     => 2016-10-21 14:15:00
'start_utc' => 2016-10-21 14:15:00

然后值 2016-10-21 14:15:00 被 API 视为 2016-10-21 14:15:00 +0200 因为 userA 时区设置为 UTC+02,并且相同的值是被 API 视为 2016-10-21 14:15:00 -0700 因为 userB 时区是 UTC-07 (在 Podio 中,在帐户设置中)。如果通过应用程序身份验证,则假定时区为 UTC

因此,如果我想设置值 2016-10-21 14:15:00 +0800(假设我想设置吉隆坡时区),那么我必须先将其转换为我自己的时区(无论在跑道账户中设置什么)设置),然后发送到跑道API,像这样:

date_as_str  = "2016-10-22 14:15:00 +08:00"  # trying to set value with UTC+08
date_with_tz = DateTime.parse(date_as_str).in_time_zone("Europe/Copenhagen") # when Copenhagen is userA's timezone
date_to_send = date_with_tz.strftime('%Y-%m-%d %H:%M:%S')
content = {'date' => {'start' => date_to_send}}
Podio.client.authenticate_with_credentials(<user A>, <pass>)
item_created_by_userA = Podio::Item.create(app_id, 'fields' => content)