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

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

例如请求

 app_id =  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 ,但是如何控制和设置这个DateTime字段的特定时区

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

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

 content = {'date' => {'start' => '2016-10-21 14:15:00'}} Podio.client.authenticate_with_credentials(, ) item_created_by_userA = Podio::Item.create(app_id, 'fields' => content) Podio.client.authenticate_with_credentials(, ) item_created_by_userB = Podio::Item.create(app_id, 'fields' => content) Podio.client.authenticate_with_app(, ) 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因为2016-10-21 14:15:00 -0700时区是UTC-07 (在Podio中,在帐户设置中)。 如果作为app进行身份validation,则假设时区为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(, ) item_created_by_userA = Podio::Item.create(app_id, 'fields' => content) 
Interesting Posts