mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-08 15:35:24 +02:00
Reverted CalendarReceiver to use GregorianCalendar
This commit is contained in:
parent
c31471c9b8
commit
63444740d2
@ -28,12 +28,10 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
|
|
||||||
import de.greenrobot.dao.query.QueryBuilder;
|
import de.greenrobot.dao.query.QueryBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
@ -192,15 +190,15 @@ public class CalendarReceiver extends BroadcastReceiver {
|
|||||||
calendarEventSpec.timestamp = calendarEvent.getBeginSeconds();
|
calendarEventSpec.timestamp = calendarEvent.getBeginSeconds();
|
||||||
calendarEventSpec.durationInSeconds = calendarEvent.getDurationSeconds(); //FIXME: leads to problems right now
|
calendarEventSpec.durationInSeconds = calendarEvent.getDurationSeconds(); //FIXME: leads to problems right now
|
||||||
if (calendarEvent.isAllDay()) {
|
if (calendarEvent.isAllDay()) {
|
||||||
//force the all day events to begin at midnight and last a whole day
|
//force the all day events to begin at midnight and last N whole days
|
||||||
OffsetDateTime o = OffsetDateTime.now();
|
Calendar c = GregorianCalendar.getInstance();
|
||||||
LocalDateTime d = LocalDateTime.ofEpochSecond(calendarEvent.getBegin()/1000, 0, o.getOffset());
|
int numDays = (int)TimeUnit.DAYS.convert(calendarEvent.getEnd()-calendarEvent.getBegin(),
|
||||||
LocalDateTime fin = LocalDateTime.ofEpochSecond(calendarEvent.getEnd()/1000, 0, o.getOffset());
|
TimeUnit.MILLISECONDS);
|
||||||
int numDays = (int)ChronoUnit.DAYS.between(d, fin);
|
c.setTimeInMillis(calendarEvent.getBegin());
|
||||||
o = OffsetDateTime.of(d, o.getOffset()).withHour(0);
|
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
//workaround for negative timezones
|
//workaround for negative timezones
|
||||||
if(o.getOffset().compareTo(ZoneOffset.UTC)>0) o = o.plusDays(1);
|
if(c.getTimeZone().getRawOffset()<0) c.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
calendarEventSpec.timestamp = (int)o.toEpochSecond();
|
calendarEventSpec.timestamp = (int) (c.getTimeInMillis() / 1000);
|
||||||
calendarEventSpec.durationInSeconds = 24 * 60 * 60 * numDays;
|
calendarEventSpec.durationInSeconds = 24 * 60 * 60 * numDays;
|
||||||
}
|
}
|
||||||
calendarEventSpec.description = calendarEvent.getDescription();
|
calendarEventSpec.description = calendarEvent.getDescription();
|
||||||
|
Loading…
Reference in New Issue
Block a user