From 87392d9fbb0289b5486496b6e6b97db1ea84e2b7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 4 Sep 2017 18:01:43 +0500 Subject: Accept timezone id instead of offset in commands --- src/org/traccar/protocol/WatchProtocolEncoder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol/WatchProtocolEncoder.java') diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index 6fcd109c2..e585a91c1 100644 --- a/src/org/traccar/protocol/WatchProtocolEncoder.java +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,13 +26,14 @@ import java.text.DecimalFormatSymbols; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.TimeZone; public class WatchProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter { @Override public String formatValue(String key, Object value) { if (key.equals(Command.KEY_TIMEZONE)) { - double offset = ((Number) value).longValue() / 3600.0; + double offset = TimeZone.getTimeZone(value.toString()).getRawOffset() / 3600000.0; DecimalFormat fmt = new DecimalFormat("+#.##;-#.##", DecimalFormatSymbols.getInstance(Locale.US)); return fmt.format(offset); } @@ -41,6 +42,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin } + @Override protected String formatCommand(Command command, String format, String... keys) { String content = super.formatCommand(command, format, this, keys); return String.format("[CS*%s*%04x*%s]", -- cgit v1.2.3 From 158071c9ff74c5435b8f51ea82215240acb69551 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 5 Sep 2017 08:58:52 +0500 Subject: Use casting and remove super --- src/org/traccar/protocol/MiniFinderProtocolEncoder.java | 2 +- src/org/traccar/protocol/Pt502ProtocolEncoder.java | 4 ++-- src/org/traccar/protocol/WatchProtocolEncoder.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/org/traccar/protocol/WatchProtocolEncoder.java') diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java index 7cf19d352..486f406a5 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java @@ -29,7 +29,7 @@ public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements if (key.equals(Command.KEY_ENABLE)) { return (Boolean) value ? "1" : "0"; } else if (key.equals(Command.KEY_TIMEZONE)) { - return String.format("%+03d", TimeZone.getTimeZone(value.toString()).getRawOffset() / 3600000); + return String.format("%+03d", TimeZone.getTimeZone((String) value).getRawOffset() / 3600000); } else if (key.equals(Command.KEY_INDEX)) { switch (((Number) value).intValue()) { case 0: diff --git a/src/org/traccar/protocol/Pt502ProtocolEncoder.java b/src/org/traccar/protocol/Pt502ProtocolEncoder.java index d5e219bd2..4a876f6da 100644 --- a/src/org/traccar/protocol/Pt502ProtocolEncoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolEncoder.java @@ -26,7 +26,7 @@ public class Pt502ProtocolEncoder extends StringProtocolEncoder implements Strin @Override public String formatValue(String key, Object value) { if (key.equals(Command.KEY_TIMEZONE)) { - return String.valueOf(TimeZone.getTimeZone(value.toString()).getRawOffset() / 3600000); + return String.valueOf(TimeZone.getTimeZone((String) value).getRawOffset() / 3600000); } return null; @@ -34,7 +34,7 @@ public class Pt502ProtocolEncoder extends StringProtocolEncoder implements Strin @Override protected String formatCommand(Command command, String format, String... keys) { - return super.formatCommand(command, format, this, keys); + return formatCommand(command, format, this, keys); } @Override diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index e585a91c1..d2d3b52d1 100644 --- a/src/org/traccar/protocol/WatchProtocolEncoder.java +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -33,7 +33,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin @Override public String formatValue(String key, Object value) { if (key.equals(Command.KEY_TIMEZONE)) { - double offset = TimeZone.getTimeZone(value.toString()).getRawOffset() / 3600000.0; + double offset = TimeZone.getTimeZone((String) value).getRawOffset() / 3600000.0; DecimalFormat fmt = new DecimalFormat("+#.##;-#.##", DecimalFormatSymbols.getInstance(Locale.US)); return fmt.format(offset); } @@ -44,7 +44,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin @Override protected String formatCommand(Command command, String format, String... keys) { - String content = super.formatCommand(command, format, this, keys); + String content = formatCommand(command, format, this, keys); return String.format("[CS*%s*%04x*%s]", getUniqueId(command.getDeviceId()), content.length(), content); } -- cgit v1.2.3