I am working on an Android application whose goal is to synchronize events between a PHP application and a smartphone. Everything works fine for "normal" events, but I have a problem with all the "all day" events. I followed the official Android documentation by setting EVENT_TIMEZONE to UTC and setting timestamps for dtstart and dtend, which corresponds to midnight UTC.
However, depending on the time zone of the phone during the creation of the event, when I open Google Calendar, the events:
- The display is correct when the phone’s time zone is GMT + 2
- Start one day before the phone’s time zone is GMT-11 → GMT + 1
- Ending the day after the phone’s time zone is GMT + 3 → GMT + 13
You should know that my tests are conducted in France, and we are now in GMT + 2. Google Calendar is configured to use the time zone of the phone.
The following is information about events before insertion:
06-22 17:41:02.339: V/EventEntity - addToCalendar(6535): Event to be inserted : calendar_id=8 dtstart=1466719200000 ( = 24/6/2016 0:00:00 ) eventLocation= title=Server AllDay Event dtend=1466805600000 ( = 25/6/2016 0:00:00 ) allDay=true description= hasAlarm=1 eventStatus=1 eventTimezone=UTC
and here is the code of the method that inserts the events where the previous log comes from:
Context context = AppContext.getAppContext(); ContentValues eventValues = this.getValuesForCalendar(); Log.v("EventEntity - addToCalendar", "Event to be inserted : " + eventValues); Uri eventUri = context.getContentResolver().insert(Uri.parse("content://com.android.calendar/events"), eventValues); this.setSystem_id(Long.parseLong(eventUri.getLastPathSegment())); // === RAPPEL DE RDV === String reminderUriString = "content://com.android.calendar/reminders"; ContentValues reminderValues = new ContentValues(); reminderValues.put("event_id", this.getSystem_id()); reminderValues.put("minutes", 5); // Default(0), Alert(1), Email(2), SMS(3) reminderValues.put("method", 0); context.getContentResolver().insert(Uri.parse(reminderUriString), reminderValues); // =====================
And yet, when events are displayed correctly, if the phone’s time zone changes, the events propagate to the previous or next day. The behavior does not match all-day events created using Google Calendar:
Events with the phone in GMT + 2:

Phone time zone events changed to GMT-1:

So, I reset the calendar with those events throughout the day that were created with my application, and the other with the Google calendar:

As you can see, an event created using Google Calendar should start at 2am, not midnight! Therefore, I tried to set dstart and dtend timestamps before midnight in the phone’s time zone (i.e., at 2 o’clock if the phone’s time zone is GMT + 2 or 23PM the day before, if GMT-1), but events still cover the previous one or the next day.
In a nutshell: I lost, and I don’t understand how to correctly conduct all the daytime events that start and end on the right day and will not move around the calendar when the phone’s time zone changes!