Podio: which TimeZone is used while setting DateTime field value

后端 未结 1 1735
走了就别回头了
走了就别回头了 2021-01-13 15:16

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

相关标签:
1条回答
  • 2021-01-13 15:36

    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)
    
    0 讨论(0)
提交回复
热议问题