diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java index 871b63bad..22d8d8001 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java @@ -219,18 +219,21 @@ public class BLETypeConversions { * @return sint8 value from -48..+56 */ public static byte mapTimeZone(TimeZone timeZone) { - return mapTimeZone(timeZone, TZ_FLAG_NONE); + int offsetMillis = timeZone.getRawOffset(); + int utcOffsetInQuarterHours = (offsetMillis / (1000 * 60 * 15)); + return (byte) utcOffsetInQuarterHours; } /** * https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.time_zone.xml - * @param timeZone + * + * @param calendar * @return sint8 value from -48..+56 */ - public static byte mapTimeZone(TimeZone timeZone, int timezoneFlags) { - int offsetMillis = timeZone.getRawOffset(); + public static byte mapTimeZone(Calendar calendar, int timezoneFlags) { + int offsetMillis = calendar.getTimeZone().getRawOffset(); if (timezoneFlags == TZ_FLAG_INCLUDE_DST_IN_TZ) { - offsetMillis += timeZone.getDSTSavings(); + offsetMillis = calendar.getTimeZone().getOffset(calendar.getTimeInMillis()); } int utcOffsetInQuarterHours = (offsetMillis / (1000 * 60 * 15)); return (byte) utcOffsetInQuarterHours; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index 70fbccf3f..6147e9b2a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -324,7 +324,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { } else { throw new IllegalArgumentException("Unsupported precision, only MINUTES and SECONDS are supported till now"); } - byte[] tail = new byte[] { 0, BLETypeConversions.mapTimeZone(calendar.getTimeZone(), BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ) }; + byte[] tail = new byte[] { 0, BLETypeConversions.mapTimeZone(calendar, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ) }; // 0 = adjust reason bitflags? or DST offset?? , timezone // byte[] tail = new byte[] { 0x2 }; // reason byte[] all = BLETypeConversions.join(bytes, tail); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java index 07d179a4f..1359b612e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java @@ -288,7 +288,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL // Since this is a standard we should generalize this in Gadgetbridge (properly) GregorianCalendar now = BLETypeConversions.createCalendar(); byte[] bytes = BLETypeConversions.calendarToRawBytes(now); - byte[] tail = new byte[]{0, BLETypeConversions.mapTimeZone(now.getTimeZone(), BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ)}; + byte[] tail = new byte[]{0, BLETypeConversions.mapTimeZone(now, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ)}; byte[] all = BLETypeConversions.join(bytes, tail); TransactionBuilder builder = new TransactionBuilder("set time");