mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Garmin: Fix crash on timezones without DST
This commit is contained in:
parent
8cf6c457ac
commit
bbadb2b1ef
@ -34,11 +34,35 @@ public class CurrentTimeRequestMessage extends GFDIMessage {
|
|||||||
final int garminTimestamp = GarminTimeUtils.unixTimeToGarminTimestamp((int) now.getEpochSecond());
|
final int garminTimestamp = GarminTimeUtils.unixTimeToGarminTimestamp((int) now.getEpochSecond());
|
||||||
final ZoneOffsetTransition nextTransitionStart = zoneRules.nextTransition(now);
|
final ZoneOffsetTransition nextTransitionStart = zoneRules.nextTransition(now);
|
||||||
|
|
||||||
final int nextTransitionStartsTs = (int) nextTransitionStart.toEpochSecond();
|
final int nextTransitionEndsGarminTs;
|
||||||
final int nextTransitionEndsTs = (int) zoneRules.nextTransition(nextTransitionStart.getInstant()).toEpochSecond();
|
final int nextTransitionStartsGarminTs;
|
||||||
|
|
||||||
|
if (nextTransitionStart != null) {
|
||||||
|
final int nextTransitionStartsTs = (int) nextTransitionStart.toEpochSecond();
|
||||||
|
nextTransitionStartsGarminTs = GarminTimeUtils.unixTimeToGarminTimestamp(nextTransitionStartsTs);
|
||||||
|
|
||||||
LOG.info("Processing current time request #{}: time={}, DST={}, ofs={}", referenceID, garminTimestamp, dstOffset, timeZoneOffset);
|
final ZoneOffsetTransition nextTransitionEnd = zoneRules.nextTransition(nextTransitionStart.getInstant());
|
||||||
|
|
||||||
|
if (nextTransitionEnd != null) {
|
||||||
|
final int nextTransitionEndsTs = (int) nextTransitionEnd.toEpochSecond();
|
||||||
|
nextTransitionEndsGarminTs = GarminTimeUtils.unixTimeToGarminTimestamp(nextTransitionEndsTs);
|
||||||
|
} else {
|
||||||
|
nextTransitionEndsGarminTs = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextTransitionEndsGarminTs = 0;
|
||||||
|
nextTransitionStartsGarminTs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info(
|
||||||
|
"Processing current time request #{}: time={}, DST={}, ofs={}, nextTransitionEnds={}, nextTransitionStarts={}",
|
||||||
|
referenceID,
|
||||||
|
garminTimestamp,
|
||||||
|
dstOffset,
|
||||||
|
timeZoneOffset,
|
||||||
|
nextTransitionEndsGarminTs,
|
||||||
|
nextTransitionStartsGarminTs
|
||||||
|
);
|
||||||
|
|
||||||
final MessageWriter writer = new MessageWriter(response);
|
final MessageWriter writer = new MessageWriter(response);
|
||||||
writer.writeShort(0); // packet size will be filled below
|
writer.writeShort(0); // packet size will be filled below
|
||||||
@ -48,8 +72,8 @@ public class CurrentTimeRequestMessage extends GFDIMessage {
|
|||||||
writer.writeInt(referenceID);
|
writer.writeInt(referenceID);
|
||||||
writer.writeInt(garminTimestamp);
|
writer.writeInt(garminTimestamp);
|
||||||
writer.writeInt(timeZoneOffset);
|
writer.writeInt(timeZoneOffset);
|
||||||
writer.writeInt(GarminTimeUtils.unixTimeToGarminTimestamp(nextTransitionEndsTs));
|
writer.writeInt(nextTransitionEndsGarminTs);
|
||||||
writer.writeInt(GarminTimeUtils.unixTimeToGarminTimestamp(nextTransitionStartsTs));
|
writer.writeInt(nextTransitionStartsGarminTs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user