Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Calendar API v3 time zone issues

Using .Net API wrapper for Google Calendar API.

  1. First get primary calendar id
  2. Get timezone of primary calendar (returns good data, e.g., "America/Los_Angeles")
  3. Create a calendar event. Set start time and end time. Set timezone.
Dim eStart As New EventDateTime
eStart.DateTime = _startAt
eStart.TimeZone = GoogleTimeZone
Dim eEnd As New EventDateTime
eEnd.DateTime = _endAt
entry.Start = eStart
entry.End = eEnd
eEnd.TimeZone = GoogleTimeZone
CalService.Events.Insert(entry, calendarid).Execute()

But the events are being created at 3am when the start time specified is 11am.

Google API documentation states "A time zone offset is required unless a time zone is explicitly specified in timeZone" and for timezone "The time zone in which the time is specified. (Formatted as an IANA Time Zone Database name, e.g. "Europe/Zurich".)".

Timezone value is being specified properly.

Basically, it is not making any difference whether or not timezone is specified. Event is created in GMT in google calendar. What is wrong here?

like image 667
Allen King Avatar asked Oct 11 '25 17:10

Allen King


1 Answers

Fixed it (or let's just say hacked it). Google .Net API wrappers are absolutely crap (and this goes to wrapper of all of their APIs and not just Calendar API).

The issue was that event.Start and event.End automatically converts dates and add a "Z" at the end. This tells Google that the date is in GMT format. There is no reason for putting a "Z" because even without it, Google considers GMT. So basically, event.TimeZone=value was being disregarded because the time was appended by "Z".

After I removed the "Z", everything worked ok.

entry.Start.DateTimeRaw = replace(entry.Start.DateTimeRaw,"Z","")
entry.End.DateTimeRaw = replace(entry.End.DateTimeRaw,"Z","")

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!