plusonelabs / calendar-widget

An calender widget for your Android home screen.
Apache License 2.0
370 stars 127 forks source link

org.joda.time.IllegalInstantException when creating calendar event #186

Closed mpost closed 9 years ago

mpost commented 9 years ago

As reported in the Google Play Store. The issue has been existing in the 1.8.x release as well but continues to appear in 1.9.x.

org.joda.time.IllegalInstantException: Illegal instant due to time zone offset transition (daylight savings time 'gap'): 1980-04-06T00:00:00.000 (Europe/Vienna)
at org.joda.time.DateTimeZone.convertLocalToUTC(DateTimeZone.java:997)
at com.plusonelabs.calendar.calendar.CalendarEventProvider.createCalendarEvent(CalendarEventProvider.java:250)
at com.plusonelabs.calendar.calendar.CalendarEventProvider.queryList(CalendarEventProvider.java:132)
at com.plusonelabs.calendar.calendar.CalendarEventProvider.getPastEventWithColorList(CalendarEventProvider.java:159)
at com.plusonelabs.calendar.calendar.CalendarEventProvider.getEvents(CalendarEventProvider.java:66)
at com.plusonelabs.calendar.calendar.CalendarEventVisualizer.getEventEntries(CalendarEventVisualizer.java:203)
at com.plusonelabs.calendar.EventRemoteViewsFactory.onDataSetChanged(EventRemoteViewsFactory.java:100)
at android.widget.RemoteViewsService$RemoteViewsFactoryAdapter.onDataSetChanged(RemoteViewsService.java:142)
at com.android.internal.widget.IRemoteViewsFactory$Stub.onTransact(IRemoteViewsFactory.java:49)
at android.os.Binder.execTransact(Binder.java:446)
yvolk commented 9 years ago

As http://joda-time.sourceforge.net/faq.html#illegalinstant tells, this is expected behaviour of Joda library. These are similar cases: http://stackoverflow.com/questions/25233776/unable-to-create-a-specific-joda-datetime-illegalinstantexception http://beust.com/weblog/2013/03/30/the-time-that-never-was/

Unfortunately, I couldn't reproduce this exception yet.

yvolk commented 9 years ago

And here is an advice on how to handle (and to reproduce?!) the problem: http://stackoverflow.com/questions/5451152/how-to-handle-jodatime-illegal-instant-due-to-time-zone-offset-transition

yvolk commented 9 years ago

Currently code crashes e.g. when Time zone in Android is set to "GMT+1:00 Central European Standard Time" (e.g. by selecting "Amsterdam" from a list):

org.joda.time.IllegalInstantException: ; startDate=2015-03-29T04:00:00.000+02:00 ( Europe/Amsterdam) caused by: org.joda.time.IllegalInstantException: Illegal instant due to time zone offset transition (daylight savings time 'gap'): 2015-03-29T02:00:00.000 (Europe/Amsterdam)

So it looks like the logic itself is wrong: we should change time not from 4AM to 2AM, but from 4AM (or any other time) to 0AM ?! ...Or, I got the logic: it assumes that Dates for All Day events are 0 hours at GMT ! The exception occurs, when there is no local time with 0 hours at this day.

yvolk commented 9 years ago

The bug is fixed and corresponding code cleaned. See com.plusonelabs.calendar.calendar.CalendarEventProvider#fixAllDayEvent

The test now passes: com.plusonelabs.calendar.WidgetEntriesTest#testIllegalInstantDueToTimeZoneOffsetTransition