Podio:在设置DateTime字段值时使用哪个TimeZone [英] Podio: which TimeZone is used while setting DateTime field value

查看:143
本文介绍了Podio:在设置DateTime字段值时使用哪个TimeZone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

While creating new item or updating existing item using Podio API, and setting DateTime field value to: 2016-10-21 14:15:00 (as example). Which timezone will be used to store this 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)

结果

'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字段?

Which is great, because I'm seeing same time value 14:15 as I've set 14:15, but how can I control and set specific timezone to this DateTime field?

推荐答案

看起来,Podio API非常聪明,并且意识到我的时区。

It appears that Podio API is pretty smart and is aware of my timezone.

以下是几个包含请求和结果的示例。
将DateTime字段设置为 14:15:00 被认证为不同的用户和应用程序。

Here are couple of examples with requests and results. Setting DateTime field to 14:15:00 being authenticated as different users and as 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)

然后设置的值为:

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

Then value 2016-10-21 14:15:00 is treated by API as 2016-10-21 14:15:00 +0200 because userA timezone is set to UTC+02, and same value is treated by API as 2016-10-21 14:15:00 -0700 because userB timezone is UTC-07 (inside Podio, in account settings). And if authenticated as app, then assumed timezone is UTC

所以,如果我想设定价值 2016-10 -21 14:15:00 +0800 (假设我想设置吉隆坡的时区),那么我将不得不将其首先转换为我自己的时区(无论在Podio帐户设置中设置) ,然后发送到Podio API,如下所示:

So, if I want to set value 2016-10-21 14:15:00 +0800 (let's pretend I want to set timezone of Kuala Lumpur), then I will have to convert it first to my own timezone (whatever is set in Podio account settings), and then send to Podio API, like this:

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)

这篇关于Podio:在设置DateTime字段值时使用哪个TimeZone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆