1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

Fix bug in non-DST time where still being in DST was assumed

This affects InfiniTime and Huami
For InfiniTime it probably resulted in the wrong time being displayed
For Huami is resulted to request the wrong data from the band/watch

We used timezone.getDSTOffset() which always returns the DST offset (also in non
DST time)

We need to pass the time being observed to calendar.getOffset() to get the real
offset including DST at that specfic time which then either includes DST offset or not.
This commit is contained in:
Andreas Shimokawa 2021-11-02 11:34:55 +01:00
parent 5ff08a031d
commit 998f8775d9
3 changed files with 10 additions and 7 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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");