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?
E.g. request:
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)
Result:
'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
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?
It appears that Podio API is pretty smart and is aware of my timezone.
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)
Then values set are:
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
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
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)