google-api-ruby-client设置错误的事件开始和结束时间

时间:2018-01-12 21:07:40

标签: ruby-on-rails ruby google-api-client google-api-ruby-client

我使用 google-api-ruby-client 来更新活动。当我提供时区为“EUROPE / LONDON”的开始和结束日期时间时,事件已成功保存,但返回的事件的开始和结束时间在太平洋时区,偏移量为-0700而不是+0000错误的活动时间。您可以在下面看到部分响应显示错误的时间偏移:

 Success - #<Google::Apis::CalendarV3::Event:0x005638691b3dc8

 @end=
   #<Google::Apis::CalendarV3::EventDateTime:0x00563869199ec8
   @date_time=Mon, 23 Apr 2018 04:45:00 -0700,
   @time_zone="Europe/London">,
 @start=
  #<Google::Apis::CalendarV3::EventDateTime:0x00563869177e90
  @date_time=Mon, 23 Apr 2018 03:45:00 -0700,
  @time_zone="Europe/London">
 >

这是进行api调用的方法:

def service 
  secrets = setup_credentials
  service = Google::Apis::CalendarV3::CalendarService.new
  service.client_options.application_name = 'Quickstart'
  service.authorization = secrets.to_authorization

  event_id = "yyyzzzzzzxxxxx"
  date_string = "2018-4-23 10:45AM"
  date = DateTime.parse(date_string)
  end_date = (date + 1.hour)

  event = {
    summary: "hype event",
    start: {date_time: date, time_zone: "Europe/London"},
    end: {date_time: end_date, time_zone: "Europe/London"}
  }
  service.update_event('primary', event_id, event, send_notifications: true) 
end

有人知道如何使google api使用我指定的time_zone。

1 个答案:

答案 0 :(得分:0)

我正在传递一个日期时间对象,例如星期一,2018年4月23日10:45:00 +0000 ,其中包含一个时区。即偏移 +0000 表示时区。这意味着Google Api忽略了我传递给api的自定义时区值。以下是避免疑问的自定义时区值: time_zone =&#34;欧洲/伦敦&#34; 。要让Google使用自定义时区,请按以下步骤操作。

从日期时间对象中删除时区/偏移量,此外,通过调用 start_date将格式更改为此&#34; 2018-04-23T10:45:00&#34; .strftime(&#39;%FT%T&#39;)其中 start_date 是包含datetime对象的变量,如星期一,2018年4月23日10:45: 00 +0000