1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-02 09:46:24 +02:00

Pebble: fix wrong calculation of timestamp.

This commit is contained in:
Andreas Shimokawa 2015-05-21 18:57:34 +02:00
parent 68b76aa5c5
commit 8309234784

View File

@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
import java.util.SimpleTimeZone; import java.util.SimpleTimeZone;
import java.util.TimeZone;
import java.util.UUID; import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBCommand; import nodomain.freeyourgadget.gadgetbridge.GBCommand;
@ -223,9 +222,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
@Override @Override
public byte[] encodeSMS(String from, String body) { public byte[] encodeSMS(String from, String body) {
Long ts = System.currentTimeMillis() / 1000; Long ts = System.currentTimeMillis();
TimeZone tz = SimpleTimeZone.getDefault(); ts += (SimpleTimeZone.getDefault().getOffset(ts));
ts += (tz.getOffset(ts) + tz.getDSTSavings()) / 1000; ts /= 1000;
if (USE_OLD_NOTIFICATION_PROTOCOL) { if (USE_OLD_NOTIFICATION_PROTOCOL) {
String[] parts = {from, body, ts.toString()}; String[] parts = {from, body, ts.toString()};
@ -238,9 +237,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
@Override @Override
public byte[] encodeEmail(String from, String subject, String body) { public byte[] encodeEmail(String from, String subject, String body) {
Long ts = System.currentTimeMillis() / 1000; Long ts = System.currentTimeMillis();
TimeZone tz = SimpleTimeZone.getDefault(); ts += (SimpleTimeZone.getDefault().getOffset(ts));
ts += (tz.getOffset(ts) + tz.getDSTSavings()) / 1000; ts /= 1000;
String tsstring = ts.toString(); // SIC String tsstring = ts.toString(); // SIC
String[] parts = {from, body, tsstring, subject}; String[] parts = {from, body, tsstring, subject};
@ -255,16 +254,15 @@ public class PebbleProtocol extends GBDeviceProtocol {
@Override @Override
public byte[] encodeSetTime(long ts) { public byte[] encodeSetTime(long ts) {
if (ts == -1) { if (ts == -1) {
ts = System.currentTimeMillis() / 1000; ts = System.currentTimeMillis();
TimeZone tz = SimpleTimeZone.getDefault(); ts += (SimpleTimeZone.getDefault().getOffset(ts));
ts += (tz.getOffset(ts) + tz.getDSTSavings()) / 1000;
} }
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SETTIME); ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SETTIME);
buf.order(ByteOrder.BIG_ENDIAN); buf.order(ByteOrder.BIG_ENDIAN);
buf.putShort(LENGTH_SETTIME); buf.putShort(LENGTH_SETTIME);
buf.putShort(ENDPOINT_TIME); buf.putShort(ENDPOINT_TIME);
buf.put(TIME_SETTIME); buf.put(TIME_SETTIME);
buf.putInt((int) ts); buf.putInt((int) (ts / 1000));
return buf.array(); return buf.array();
} }