Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change an event from all-day to time-limited

There's an all-day event on Google calendar, I pulled it, change it to 1-hour event, I created patch event to push back. As I understand, an all-day event has "start" as a Date, and "end" as the following date. Time-limited event have those in DateTime.

So in my patch, I tried changing those values from Date to DateTime. However, I always receive the error "Invalid or mismatching start and end times".

I tried this manually on Google Calendar API site: https://developers.google.com/google-apps/calendar/v3/reference/events/patch#try-it and getting the same error. If I take a time-limited event and modify it, no trouble occurs. I believe this is a bug in the API itself. Anyone experiences it and what's the workaround? Thanks in advance.

like image 696
EyeQ Tech Avatar asked Dec 18 '12 06:12

EyeQ Tech


1 Answers

Updated: this is what I received from google dev team, hope useful to sb:

Comment #4 on issue 3110 by [email protected]: patching event from all-day to non all-day failed http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3110

Patch operation takes the original event and changes/adds/removes entries specified by the request. If you send following request to PATCH operation against all-day event:

{
 "start": {
  "dateTime": "2012-05-17T06:30:00+06:30",
  "timeZone": "UTC"
 },
 "end": {
  "dateTime": "2012-05-17T07:30:00+06:30",
  "timeZone": "UTC"
 }
}

the resulting event would end-up with both dateTime and date fields set (which is not allowed). Hence, the PATCH request needs to clear the date fields:

{
 "start": {
  "dateTime": "2012-05-17T06:30:00+06:30",
  "timeZone": "UTC",
  "date": null
 },
 "end": {
  "dateTime": "2012-05-17T07:30:00+06:30",
  "timeZone": "UTC",
  "date": null
 }
}

In code, when you want to set the field Date to null, you have to put Data.NULL_DATE_TIME like this:

EventDateTime edt = new EventDateTime();
edt.put("date",Data.NULL_DATE_TIME);// if you put NULL, it doesn't retain.
edt.put("dateTime", newTime); //newTime is the new value you want to set, type DateTime
like image 189
EyeQ Tech Avatar answered Sep 20 '22 22:09

EyeQ Tech