aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-13 10:34:02 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-13 10:34:02 +1300
commite997c2642b35350241614acaef6d606e37223fe6 (patch)
tree145cd9817c3b8d4954200ada5012b91719697f8f /src
parent797263bfe9655ac82a97954c6930ec4a650a0609 (diff)
downloadtrackermap-server-e997c2642b35350241614acaef6d606e37223fe6.tar.gz
trackermap-server-e997c2642b35350241614acaef6d606e37223fe6.tar.bz2
trackermap-server-e997c2642b35350241614acaef6d606e37223fe6.zip
Extend date builder interface
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/helper/DateBuilder.java18
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java16
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java2
3 files changed, 23 insertions, 13 deletions
diff --git a/src/org/traccar/helper/DateBuilder.java b/src/org/traccar/helper/DateBuilder.java
index e0e9e0cab..17936a329 100644
--- a/src/org/traccar/helper/DateBuilder.java
+++ b/src/org/traccar/helper/DateBuilder.java
@@ -55,6 +55,18 @@ public class DateBuilder {
return setYear(year).setMonth(month).setDay(day);
}
+ public DateBuilder setDateReverse(int day, int month, int year) {
+ return setDate(year, month, day);
+ }
+
+ public DateBuilder setDate(String year, String month, String day) {
+ return setDate(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
+ }
+
+ public DateBuilder setDateReverse(String day, String month, String year) {
+ return setDate(year, month, day);
+ }
+
public DateBuilder setHour(int hour) {
calendar.set(Calendar.HOUR_OF_DAY, hour);
return this;
@@ -79,6 +91,10 @@ public class DateBuilder {
return setHour(hour).setMinute(minute).setSecond(second);
}
+ public DateBuilder setTime(String hour, String minute, String second) {
+ return setTime(Integer.parseInt(hour), Integer.parseInt(minute), Integer.parseInt(second));
+ }
+
public DateBuilder setTime(int hour, int minute, int second, int millis) {
return setHour(hour).setMinute(minute).setSecond(second).setMillis(millis);
}
@@ -87,7 +103,7 @@ public class DateBuilder {
return setDate(year, month, day).setTime(hour, minute, second);
}
- public Date build() {
+ public Date getDate() {
return calendar.getTime();
}
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index ad6a5a574..920f6dc36 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -16,16 +16,15 @@
package org.traccar.protocol;
import java.net.SocketAddress;
-import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
-import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.BitUtil;
+import org.traccar.helper.DateBuilder;
import org.traccar.helper.PatternBuilder;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -164,20 +163,15 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- time.clear();
- time.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parser.group(index++)));
- time.set(Calendar.MINUTE, Integer.parseInt(parser.group(index++)));
- time.set(Calendar.SECOND, Integer.parseInt(parser.group(index++)));
- time.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parser.group(index++)));
- time.set(Calendar.MONTH, Integer.parseInt(parser.group(index++)) - 1);
- time.set(Calendar.YEAR, 2000 + Integer.parseInt(parser.group(index++)));
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.group(index++), parser.group(index++), parser.group(index++))
+ .setDateReverse(parser.group(index++), parser.group(index++), parser.group(index++));
List<Position> positions = new LinkedList<>();
Matcher itemParser = PATTERN_ITEM.matcher(parser.group(index++));
while (itemParser.find()) {
- positions.add(decodePosition(itemParser, time.getTime()));
+ positions.add(decodePosition(itemParser, dateBuilder.getDate()));
}
return positions;
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index 5d79958a5..ffdbdf17b 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -161,7 +161,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
DateBuilder dateBuilder = new DateBuilder(timeZone)
.setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.build());
+ position.setTime(dateBuilder.getDate());
// GPS length and Satellites count
int gpsLength = buf.readUnsignedByte();