1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-02 11:26:09 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/GarminTimeUtils.java
Daniele Gobbetti 7ee82e6afa Garmin protocol: add initial support for FIT messages
note: only weather message definition and data tested so far
also enable weather support for Instinct 2S and vivomove style
also cleanup some unused constants that have been migrated to new enums in GFDIMessage
additionally switch to new local implementation of GarminTimeUtils with needed methods
2024-05-01 23:35:15 +01:00

30 lines
905 B
Java

package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin;
import org.threeten.bp.Instant;
import org.threeten.bp.ZoneId;
public class GarminTimeUtils {
private static final int GARMIN_TIME_EPOCH = 631065600;
public static int unixTimeToGarminTimestamp(int unixTime) {
return unixTime - GARMIN_TIME_EPOCH;
}
public static int javaMillisToGarminTimestamp(long millis) {
return (int) (millis / 1000) - GARMIN_TIME_EPOCH;
}
public static long garminTimestampToJavaMillis(int timestamp) {
return (timestamp + GARMIN_TIME_EPOCH) * 1000L;
}
public static int garminTimestampToUnixTime(int timestamp) {
return timestamp + GARMIN_TIME_EPOCH;
}
public static int unixTimeToGarminDayOfWeek(int unixTime) {
return (Instant.ofEpochSecond(unixTime).atZone(ZoneId.systemDefault()).getDayOfWeek().getValue() % 7);
}
}