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

Pav*_*dio 4 ruby datetime podio

使用Podio API创建新项目或更新现有项目时,将DateTime字段值设置为:( 2016-10-21 14:15:00作为示例).哪个时区将用于存储此DateTime?

例如请求:

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)
Run Code Online (Sandbox Code Playgroud)

结果:

'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
Run Code Online (Sandbox Code Playgroud)

这很好,因为我看到的时间值14:15与我设置的相同14:15,但是如何控制和设置此DateTime字段的特定时区

Pav*_*dio 6

看起来Podio API非常聪明,并且知道我的时区.

以下是一些包含请求和结果的示例.将DateTime字段设置14:15:00为作为不同用户和app进行身份验证.

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)
Run Code Online (Sandbox Code Playgroud)

然后设置的值是:

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
Run Code Online (Sandbox Code Playgroud)

然后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中,在帐户设置中).如果作为app进行身份验证,则假设时区为UTC

所以,如果我想设置值2016-10-21 14:15:00 +0800(让我假装我想设置吉隆坡的时区),那么我将首先将它转换为我自己的时区(无论在Podio帐户设置中设置什么),然后发送到Podio 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)
Run Code Online (Sandbox Code Playgroud)