From 78d7d9cb121115b064a6c9ed8fcaccc2dfd0a825 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 26 Jul 2018 01:33:29 +1200 Subject: Make Huabao timezone configurable --- src/org/traccar/BaseProtocolDecoder.java | 6 +++++- src/org/traccar/protocol/HuabaoProtocolDecoder.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index fe41bd857..d7ccb6460 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -82,7 +82,11 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } protected TimeZone getTimeZone(long deviceId) { - TimeZone result = TimeZone.getTimeZone("UTC"); + return getTimeZone(deviceId, "UTC"); + } + + protected TimeZone getTimeZone(long deviceId, String defaultTimeZone) { + TimeZone result = TimeZone.getTimeZone(defaultTimeZone); String timeZoneName = null; if (Context.getDeviceManager() != null) { timeZoneName = Context.getDeviceManager().lookupAttributeString( diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java index b92840dfc..e5ee30fcf 100644 --- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -120,6 +120,10 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { return null; } + if (deviceSession.getTimeZone() == null) { + deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId(), "GMT+8")); + } + if (type == MSG_TERMINAL_REGISTER) { if (channel != null) { @@ -180,7 +184,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1)); position.setCourse(buf.readUnsignedShort()); - DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+8")) + DateBuilder dateBuilder = new DateBuilder(deviceSession.getTimeZone()) .setYear(BcdUtil.readInteger(buf, 2)) .setMonth(BcdUtil.readInteger(buf, 2)) .setDay(BcdUtil.readInteger(buf, 2)) -- cgit v1.2.3