diff options
author | Leandro Silva Ferreira <leandrosilvaferreira@gmail.com> | 2012-08-07 12:27:01 -0400 |
---|---|---|
committer | Leandro Silva Ferreira <leandrosilvaferreira@gmail.com> | 2012-08-07 12:27:01 -0400 |
commit | 356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e (patch) | |
tree | 03d9f0656322d44f60565cbc835d18ebffac0296 | |
parent | be061beae7ee71d6ed8666ff733600b2b2f7d354 (diff) | |
download | traccar-server-356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e.tar.gz traccar-server-356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e.tar.bz2 traccar-server-356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e.zip |
Corrected time zones bugs.
-rw-r--r-- | src/org/traccar/protocol/ST210ProtocolDecoder.java | 48 |
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; } |