From c4d2cf73f5a66759f7940ba4c11ec63976c05367 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 23 Nov 2023 13:37:36 -0800 Subject: Improve GT06 timezone handling --- .../org/traccar/protocol/Gt06ProtocolDecoder.java | 31 +++++++++------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index cf7cd12d3..7ee47dd86 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -480,28 +480,21 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // type deviceSession = getDeviceSession(channel, remoteAddress, imei); - if (deviceSession != null && !deviceSession.contains(DeviceSession.KEY_TIMEZONE)) { - deviceSession.set(DeviceSession.KEY_TIMEZONE, getTimeZone(deviceSession.getDeviceId())); - } - - if (dataLength > 10) { - int extensionBits = buf.readUnsignedShort(); - int hours = (extensionBits >> 4) / 100; - int minutes = (extensionBits >> 4) % 100; - int offset = (hours * 60 + minutes) * 60; - if ((extensionBits & 0x8) != 0) { - offset = -offset; - } - if (deviceSession != null) { - TimeZone timeZone = deviceSession.get(DeviceSession.KEY_TIMEZONE); - if (timeZone.getRawOffset() == 0) { - timeZone.setRawOffset(offset * 1000); - deviceSession.set(DeviceSession.KEY_TIMEZONE, timeZone); + if (deviceSession != null) { + TimeZone timeZone = getTimeZone(deviceSession.getDeviceId(), null); + if (timeZone == null && dataLength > 10) { + int extensionBits = buf.readUnsignedShort(); + int hours = (extensionBits >> 4) / 100; + int minutes = (extensionBits >> 4) % 100; + int offset = (hours * 60 + minutes) * 60; + if ((extensionBits & 0x8) != 0) { + offset = -offset; } + timeZone = TimeZone.getTimeZone("UTC"); + timeZone.setRawOffset(offset * 1000); } - } + deviceSession.set(DeviceSession.KEY_TIMEZONE, timeZone); - if (deviceSession != null) { sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null); } -- cgit v1.2.3