aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-02-12 21:11:16 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-02-12 21:11:16 +1300
commit5548bf13796fe08b32ebf95ed4c47382382ab721 (patch)
tree15c440e8c0e37efa45dc0f4c443c3fbe53543236
parent9b5a19002940d067284a3e3ae7d7cfd24e4d9bff (diff)
downloadtrackermap-server-5548bf13796fe08b32ebf95ed4c47382382ab721.tar.gz
trackermap-server-5548bf13796fe08b32ebf95ed4c47382382ab721.tar.bz2
trackermap-server-5548bf13796fe08b32ebf95ed4c47382382ab721.zip
Improve timezone handling
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java26
-rw-r--r--test/org/traccar/protocol/Gps103ProtocolDecoderTest.java3
2 files changed, 24 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index e79ae109f..8980c702f 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -45,10 +45,11 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
"imei:" +
"(\\d+)," + // IMEI
"([^,]+)," + // Alarm
- "(\\d{2})(\\d{2})(\\d{2})\\d+," + // Date
+ "(\\d{2})(\\d{2})(\\d{2})" + // Local Date
+ "(\\d{2})(\\d{2})," + // Local Time
"[^,]*," +
"[FL]," + // F - full / L - low
- "(\\d{2})(\\d{2})(\\d{2})\\.(\\d{3})," + // Time (HHMMSS.SSS)
+ "(\\d{2})(\\d{2})(\\d{2})\\.(\\d{3})," + // Time UTC (HHMMSS.SSS)
"([AV])," + // Validity
"(\\d{2})(\\d{2}\\.\\d{4})," + // Latitude (DDMM.MMMM)
"([NS])," +
@@ -106,19 +107,34 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.append("<alarm>");
extendedInfo.append(parser.group(index++));
extendedInfo.append("</alarm>");
-
+
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
+
+ int localHours = Integer.valueOf(parser.group(index++));
+ int localMinutes = Integer.valueOf(parser.group(index++));
+
+ int utcHours = Integer.valueOf(parser.group(index++));
+ int utcMinutes = Integer.valueOf(parser.group(index++));
// Time
- time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++)));
- time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++)));
+ time.set(Calendar.HOUR, localHours);
+ time.set(Calendar.MINUTE, localMinutes);
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++)));
+
+ // Timezone calculation
+ int deltaMinutes = (localHours - utcHours) * 60 + localMinutes - utcMinutes;
+ if (deltaMinutes <= -12 * 60) {
+ deltaMinutes += 24 * 60;
+ } else if (deltaMinutes > 12) {
+ deltaMinutes -= 24 * 60;
+ }
+ time.add(Calendar.MINUTE, deltaMinutes);
position.setTime(time.getTime());
// Validity
diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
index 9c294d657..24289822a 100644
--- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
@@ -20,6 +20,9 @@ public class Gps103ProtocolDecoderTest {
// No GPS signal
//assertNull(decoder.decode(null, null, "imei:359586015829802,tracker,000000000,13554900601,L,;"));
+
+ assertNotNull(decoder.decode(null, null,
+ "imei:353451047570260,tracker,1302110948,,F,144807.000,A,0805.6615,S,07859.9763,W,0.00,,"));
assertNotNull(decoder.decode(null, null,
"imei:359587016817564,tracker,1301251602,,F,080251.000,A,3223.5832,N,11058.9449,W,0.03,"));