aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro Silva Ferreira <leandrosilvaferreira@gmail.com>2012-08-07 12:27:01 -0400
committerLeandro Silva Ferreira <leandrosilvaferreira@gmail.com>2012-08-07 12:27:01 -0400
commit356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e (patch)
tree03d9f0656322d44f60565cbc835d18ebffac0296
parentbe061beae7ee71d6ed8666ff733600b2b2f7d354 (diff)
downloadtrackermap-server-356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e.tar.gz
trackermap-server-356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e.tar.bz2
trackermap-server-356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e.zip
Corrected time zones bugs.
-rw-r--r--src/org/traccar/protocol/ST210ProtocolDecoder.java48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java
index 8745941cb..8348f5a14 100644
--- a/src/org/traccar/protocol/ST210ProtocolDecoder.java
+++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java
@@ -1,6 +1,7 @@
package org.traccar.protocol;
import java.util.Calendar;
+import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
@@ -97,34 +98,41 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder {
case DATE: {
// Date
- Calendar time = Calendar.getInstance(TimeZone
- .getTimeZone("UTC"));
+ Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
- time.set(Calendar.YEAR, Integer.valueOf(Integer
- .valueOf(groupValue.substring(0, 4))));
- time.set(Calendar.MONTH, Integer.valueOf(Integer
- .valueOf(groupValue.substring(4, 6))));
- time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer
- .valueOf(groupValue.substring(6, 8))));
- position.setTime(time.getTime());
+ time.set(Calendar.YEAR, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 4))));
+ time.set(Calendar.MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(4, 6))-1));
+ time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8))));
+
+ Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
+
+ ret.setTimeInMillis(time.getTimeInMillis() +
+ TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) -
+ TimeZone.getDefault().getOffset(time.getTimeInMillis()));
+
+ position.setTime(ret.getTime());
+
break;
}
case TIME: {
- Calendar time = Calendar.getInstance(TimeZone
- .getTimeZone("UTC"));
+ Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
time.setTime(position.getTime());
-
- time.set(Calendar.HOUR, Integer.valueOf(Integer
- .valueOf(groupValue.substring(0, 2))));
- time.set(Calendar.MINUTE, Integer.valueOf(Integer
- .valueOf(groupValue.substring(3, 5))));
- time.set(Calendar.SECOND, Integer.valueOf(Integer
- .valueOf(groupValue.substring(6, 8))));
-
- position.setTime(time.getTime());
+
+ time.set(Calendar.HOUR_OF_DAY, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 2))));
+ time.set(Calendar.MINUTE, Integer.valueOf(Integer.valueOf(groupValue.substring(3, 5))));
+ time.set(Calendar.SECOND, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8))));
+
+ Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
+
+ ret.setTimeInMillis(time.getTimeInMillis() +
+ TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) -
+ TimeZone.getDefault().getOffset(time.getTimeInMillis()));
+
+ position.setTime(ret.getTime());
+
break;
}