mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 03:16:51 +01:00
Improved mechanism for allDay calendar events
Using newer java apis instead of GregorianCalendar and fixed wrong date on negative time zones
This commit is contained in:
parent
29e0879381
commit
e6411d8f68
@ -28,9 +28,11 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Enumeration;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -190,10 +192,12 @@ public class CalendarReceiver extends BroadcastReceiver {
|
||||
calendarEventSpec.durationInSeconds = calendarEvent.getDurationSeconds(); //FIXME: leads to problems right now
|
||||
if (calendarEvent.isAllDay()) {
|
||||
//force the all day events to begin at midnight and last a whole day
|
||||
Calendar c = GregorianCalendar.getInstance();
|
||||
c.setTimeInMillis(calendarEvent.getBegin());
|
||||
c.set(Calendar.HOUR, 0);
|
||||
calendarEventSpec.timestamp = (int) (c.getTimeInMillis() / 1000);
|
||||
OffsetDateTime o = OffsetDateTime.now();
|
||||
LocalDateTime d = LocalDateTime.ofEpochSecond(calendarEvent.getBegin()/1000, 0, o.getOffset());
|
||||
o = OffsetDateTime.of(d, o.getOffset()).withHour(0);
|
||||
//workaround for negative timezones
|
||||
if(o.getOffset().compareTo(ZoneOffset.UTC)>0) o = o.plusDays(1);
|
||||
calendarEventSpec.timestamp = (int)o.toEpochSecond();
|
||||
calendarEventSpec.durationInSeconds = 24 * 60 * 60;
|
||||
}
|
||||
calendarEventSpec.description = calendarEvent.getDescription();
|
||||
|
Loading…
Reference in New Issue
Block a user