aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
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 /src/org/traccar/protocol
parent9b5a19002940d067284a3e3ae7d7cfd24e4d9bff (diff)
downloadtrackermap-server-5548bf13796fe08b32ebf95ed4c47382382ab721.tar.gz
trackermap-server-5548bf13796fe08b32ebf95ed4c47382382ab721.tar.bz2
trackermap-server-5548bf13796fe08b32ebf95ed4c47382382ab721.zip
Improve timezone handling
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java26
1 files changed, 21 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