Home google-api-ruby-client setting wrong event start and end time
Reply: 1

google-api-ruby-client setting wrong event start and end time

brg
1#
brg Published in 2018-01-12 21:07:39Z

I using the google-api-ruby-client to update an event. When I provide a start and end datetime with a time zone of "EUROPE/LONDON", the event is successfully saved but returns an event whose start and end time is in the Pacific time zone with an offset of -0700 instead of +0000 therefore the wrong time for the event. You can see part of the response below showing the wrong time offset:

 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">
 >

This is the method making the api call:

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

Does someone know how to make the google api use the time_zone I have specified.

brg
2#
brg Reply to 2018-01-18 14:57:50Z

I was passing a datetime object eg Mon, 23 Apr 2018 10:45:00 +0000 that contained a timezone. That is the offset +0000 indicates the timezone. This meant Google Api was ignoring the custom timezone value that I passed to the api. Here is the custom timezone value for the avoidance of doubt: time_zone="Europe/London". To make Google use the custom timezone, follow the steps below.

Remove the timezone/ offset froM the datetime object and in addition, change the format to this "2018-04-23T10:45:00" by calling start_date.strftime('%FT%T') where start_date is the variable that contained the datetime object as in Mon, 23 Apr 2018 10:45:00 +0000.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.346259 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO