diff options
author | jon-stumpf <jon.stumpf@gmail.com> | 2017-03-12 11:50:59 -0400 |
---|---|---|
committer | jon-stumpf <jon.stumpf@gmail.com> | 2017-03-12 11:58:08 -0400 |
commit | 2ba06b327a08432ebfc9e8a41a36bf124e087af6 (patch) | |
tree | f92d6aab1192a6f53eb2f43d50463159a164baa9 /src | |
parent | 9c6706bc8ae37776689c61e237978b364fb392e8 (diff) | |
download | traccar-server-2ba06b327a08432ebfc9e8a41a36bf124e087af6.tar.gz traccar-server-2ba06b327a08432ebfc9e8a41a36bf124e087af6.tar.bz2 traccar-server-2ba06b327a08432ebfc9e8a41a36bf124e087af6.zip |
Implemented Parser.nextDateTime();
Diffstat (limited to 'src')
65 files changed, 387 insertions, 548 deletions
diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java index d64993ccb..b345bfab2 100644 --- a/src/org/traccar/helper/Parser.java +++ b/src/org/traccar/helper/Parser.java @@ -15,13 +15,15 @@ */ package org.traccar.helper; +import java.util.Date; +import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Parser { private int position; - private Matcher matcher; + private final Matcher matcher; public Parser(Pattern pattern, String input) { matcher = pattern.matcher(input); @@ -165,4 +167,157 @@ public class Parser { return nextCoordinate(CoordinateFormat.DEG_MIN_HEM); } + public enum DateTimeFormat { + HMS, // HHMMSS + SMH, // SSMMHH + + HMS_Y4MD, // HHMMSSYYYYMMDD + HMS_Y2MD, // HHMMSSYYMMDD + + HMS_DMY4, // HHMMSSDDMMYYYY + HMS_DMY2, // HHMMSSDDMMYY + + SMH_Y4MD, // SSMMHHYYYYMMD + SMH_Y2MD, // SSMMHHYYMMDD + + SMH_DMY4, // SSMMHHDDMMYYYY + SMH_DMY2, // SSMMHHDDMMYY + + DMY4_HMS, // DDMMYYYYHHMMSS + DMY4_HMSms, // DDMMYYYYHHMMSS.m+ + DMY2_HMS, // DDMMYYHHMMSS + DMY2_HMSms, // DDMMYYHHMMSS.m+ + + Y4MD_HMS, // YYYYMMDDHHMMSS + Y4MD_HMSms, // YYYYMMDDHHMMSS.m+ + Y2MD_HMS, // YYMMDDHHMMSS + Y2MD_HMSms, // YYMMDDHHMMSS.m+ + + ISO8601 // YYYY-MM-DDTHH:MM:SS+HH:MM + } + + private static final DateTimeFormat DEFAULT_FORMAT = DateTimeFormat.Y4MD_HMS; + private static final String DEFAULT_TZ = "UTC"; + private static final int DEFAULT_RADIX = 10; + + public Date nextDateTime(DateTimeFormat format, String tz, int radix) { + int year = 0, month = 0, day = 0; + int hour = 0, minute = 0, second = 0, millisecond = 0; + TimeZone timeZone = TimeZone.getTimeZone(tz); + + switch (format) { + case HMS: + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); // (d{2})(d{2})(d{2}) + break; + case SMH: + second = nextInt(radix); minute = nextInt(radix); hour = nextInt(radix); // (d{2})(d{2})(d{2}) + break; + case HMS_Y4MD: + case HMS_Y2MD: + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); // (d{2})(d{2})(d{2}) + year = nextInt(radix); month = nextInt(radix); day = nextInt(radix); // (d{2}|d{4})(d{2})(d{2}) + break; + case HMS_DMY4: + case HMS_DMY2: + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); // (d{2})(d{2})(d{2}) + day = nextInt(radix); month = nextInt(radix); year = nextInt(radix); // (d{2})(d{2})(d{2}|d{4}) + break; + case SMH_Y4MD: + case SMH_Y2MD: + second = nextInt(radix); minute = nextInt(radix); hour = nextInt(radix); // (d{2})(d{2})(d{2}) + year = nextInt(radix); month = nextInt(radix); day = nextInt(radix); // (d{2}|d{4})(d{2})(d{2}) + break; + case SMH_DMY4: + case SMH_DMY2: + second = nextInt(radix); minute = nextInt(radix); hour = nextInt(radix); // (d{2})(d{2})(d{2}) + day = nextInt(radix); month = nextInt(radix); year = nextInt(radix); // (d{2})(d{2})(d{2}|d{4}) + break; + case DMY4_HMS: + case DMY4_HMSms: + case DMY2_HMS: + case DMY2_HMSms: + day = nextInt(radix); month = nextInt(radix); year = nextInt(radix); // (d{2})(d{2})(d{2}|d{4}) + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); // (d{2})(d{2})(d{2}) + break; + case Y4MD_HMS: + case Y4MD_HMSms: + case Y2MD_HMS: + case Y2MD_HMSms: + case ISO8601: + default: + year = nextInt(radix); month = nextInt(radix); day = nextInt(radix); // (d{2}|d{4})(d{2})(d{2}) + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); // (d{2})(d{2})(d{2}) + break; + } + + switch (format) { + case HMS_Y2MD: + case HMS_DMY2: + case SMH_Y2MD: + case SMH_DMY2: + case DMY2_HMS: + case DMY2_HMSms: + case Y2MD_HMS: + case Y2MD_HMSms: + if (year >= 0 && year < 100) { + year += 2000; // Future Y3K issue :) + } + break; + case ISO8601: + timeZone = TimeZone.getTimeZone("GMT" + next()); // ([+-]d{2}:d{2}) + break; + default: + break; + } + + switch (format) { + case Y4MD_HMSms: + case Y2MD_HMSms: + case DMY4_HMSms: + case DMY2_HMSms: + millisecond = nextInt(radix); // (d+) + break; + default: + break; + } + + DateBuilder dateBuilder = new DateBuilder(timeZone); + + if (format != DateTimeFormat.HMS || format != DateTimeFormat.SMH) { + dateBuilder.setDate(year, month, day); + } + + dateBuilder.setTime(hour, minute, second, millisecond); + + return dateBuilder.getDate(); + } + + public Date nextDateTime(String tz, int radix) { + return nextDateTime(DEFAULT_FORMAT, tz, radix); + } + + public Date nextDateTime(DateTimeFormat format, int radix) { + return nextDateTime(format, DEFAULT_TZ, radix); + } + + public Date nextDateTime(DateTimeFormat format, String tz) { + return nextDateTime(format, tz, DEFAULT_RADIX); + } + + public Date nextDateTime(DateTimeFormat format) { + return nextDateTime(format, DEFAULT_TZ, DEFAULT_RADIX); + } + + public Date nextDateTime(String tz) { + return nextDateTime(DEFAULT_FORMAT, tz, DEFAULT_RADIX); + } + + public Date nextDateTime(int radix) { + return nextDateTime(DEFAULT_FORMAT, DEFAULT_TZ, radix); + } + + public Date nextDateTime() { + return nextDateTime(DEFAULT_FORMAT, DEFAULT_TZ, DEFAULT_RADIX); + } + } diff --git a/src/org/traccar/protocol/AppelloProtocolDecoder.java b/src/org/traccar/protocol/AppelloProtocolDecoder.java index 02c966834..cc8fc061b 100644 --- a/src/org/traccar/protocol/AppelloProtocolDecoder.java +++ b/src/org/traccar/protocol/AppelloProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -71,10 +70,7 @@ public class AppelloProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); } else { getLastLocation(position, null); } diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java index 2bc3b3a09..182fb5080 100644 --- a/src/org/traccar/protocol/AquilaProtocolDecoder.java +++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -121,10 +120,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setValid(parser.next().equals("A")); diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java index 71beb7d1d..edf55a8d6 100644 --- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -66,10 +65,7 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/ArknavProtocolDecoder.java b/src/org/traccar/protocol/ArknavProtocolDecoder.java index d6abd4134..ce47f0419 100644 --- a/src/org/traccar/protocol/ArknavProtocolDecoder.java +++ b/src/org/traccar/protocol/ArknavProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -45,8 +44,8 @@ public class ArknavProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*),") // speed .number("(d+.?d*),") // course .number("(d+.?d*),") // hdop - .number("(dd):(dd):(dd) ") // time - .number("(dd)-(dd)-(dd),") // date + .number("(dd):(dd):(dd) ") // time (hh:mm:ss) + .number("(dd)-(dd)-(dd),") // date (dd-mm-yy) .any() .compile(); @@ -76,10 +75,7 @@ public class ArknavProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_HDOP, parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2)); return position; } diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java index 24c155c84..08420677b 100644 --- a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java +++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -35,7 +34,7 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression("(..),") // type .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity .number("(d+)(dd.d+)([NS]),") // latitude .number("(d+)(dd.d+)([EW]),") // longitude @@ -72,10 +71,7 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_TYPE, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/AuroProtocolDecoder.java b/src/org/traccar/protocol/AuroProtocolDecoder.java index 26bf7dfc8..c5c9c1dcb 100644 --- a/src/org/traccar/protocol/AuroProtocolDecoder.java +++ b/src/org/traccar/protocol/AuroProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -44,8 +43,8 @@ public class AuroProtocolDecoder extends BaseProtocolDecoder { .number("d{10}") // status .number("([-+])(ddd)(dd)(dddd)") // longitude .number("([-+])(ddd)(dd)(dddd)") // latitude - .number("(dd)(dd)(dddd)") // date - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dddd)") // date (ddmmyyyy) + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(ddd)") // course .number("d{6}") .number("(ddd)") // speed @@ -78,10 +77,7 @@ public class AuroProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN)); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY4_HMS)); position.setCourse(parser.nextDouble()); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java index e4dcd6ad7..bbb0d284e 100644 --- a/src/org/traccar/protocol/BoxProtocolDecoder.java +++ b/src/org/traccar/protocol/BoxProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -35,8 +34,8 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("L,") - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .text("G,") .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude @@ -82,10 +81,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.setProtocol(getProtocolName()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/CarcellProtocolDecoder.java b/src/org/traccar/protocol/CarcellProtocolDecoder.java index b41f14ad5..9c37656c3 100644 --- a/src/org/traccar/protocol/CarcellProtocolDecoder.java +++ b/src/org/traccar/protocol/CarcellProtocolDecoder.java @@ -21,7 +21,6 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.Parser.CoordinateFormat; import org.traccar.helper.PatternBuilder; @@ -57,8 +56,8 @@ public class CarcellProtocolDecoder extends BaseProtocolDecoder { .number("(d),") // jamming .number("(d+),") // hdop .expression("([CG]),?") // clock type - .number("(dd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d),") // block .number("(d),") // ignition .groupBegin() @@ -129,10 +128,7 @@ public class CarcellProtocolDecoder extends BaseProtocolDecoder { position.set("clockType", parser.next()); - DateBuilder dateBuilder = new DateBuilder(). - setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.set("blocked", parser.next().equals("1")); position.set(Position.KEY_IGNITION, parser.next().equals("1")); diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java index 0f58a24c7..59a10d804 100644 --- a/src/org/traccar/protocol/CguardProtocolDecoder.java +++ b/src/org/traccar/protocol/CguardProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -35,8 +34,8 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_NV = new PatternBuilder() .text("NV:") - .number("(dd)(dd)(dd) ") // date - .number("(dd)(dd)(dd):") // time + .number("(dd)(dd)(dd) ") // date (yymmdd) + .number("(dd)(dd)(dd):") // time (hhmmss) .number("(-?d+.d+):") // longitude .number("(-?d+.d+):") // latitude .number("(d+.?d*):") // speed @@ -47,8 +46,8 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_BC = new PatternBuilder() .text("BC:") - .number("(dd)(dd)(dd) ") // date - .number("(dd)(dd)(dd):") // time + .number("(dd)(dd)(dd) ") // date (yymmdd) + .number("(dd)(dd)(dd):") // time (hhmmss) .expression("(.+)") // data .compile(); @@ -63,10 +62,7 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setValid(true); position.setLatitude(parser.nextDouble()); @@ -92,11 +88,7 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); String[] data = parser.next().split(":"); for (int i = 0; i < data.length / 2; i++) { diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java index 2351232f9..a9fee9fe7 100644 --- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.java @@ -21,7 +21,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Checksum; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.CellTower; @@ -40,8 +39,8 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .groupBegin() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("([AV]),") // validity .number("(d+),") // satellites .number("([NS]),(d+.d+),") // latitude @@ -98,10 +97,7 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext(15)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); position.set(Position.KEY_SATELLITES, parser.next()); diff --git a/src/org/traccar/protocol/CradlepointProtocolDecoder.java b/src/org/traccar/protocol/CradlepointProtocolDecoder.java index b9e1a3e86..0656b831f 100644 --- a/src/org/traccar/protocol/CradlepointProtocolDecoder.java +++ b/src/org/traccar/protocol/CradlepointProtocolDecoder.java @@ -18,13 +18,11 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.Date; import java.util.regex.Pattern; public class CradlepointProtocolDecoder extends BaseProtocolDecoder { @@ -35,7 +33,7 @@ public class CradlepointProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression("([^,]+),") // id - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d+)(dd.d+),") // latitude .expression("([NS]),") .number("(d+)(dd.d+),") // longitude @@ -69,9 +67,7 @@ public class CradlepointProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder(new Date()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS)); position.setValid(true); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/DishaProtocolDecoder.java b/src/org/traccar/protocol/DishaProtocolDecoder.java index 6b4f91833..43019f05d 100644 --- a/src/org/traccar/protocol/DishaProtocolDecoder.java +++ b/src/org/traccar/protocol/DishaProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -36,7 +35,7 @@ public class DishaProtocolDecoder extends BaseProtocolDecoder { .text("$A#A#") .number("(d+)#") // imei .expression("([AVMX])#") // validity - .number("(dd)(dd)(dd)#") // time + .number("(dd)(dd)(dd)#") // time (hhmmss) .number("(dd)(dd)(dd)#") // date (ddmmyy) .number("(dd)(dd.d+)#") // latitude .expression("([NS])#") @@ -77,10 +76,7 @@ public class DishaProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2)); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java index c4baad5ab..d40c9a670 100644 --- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -38,16 +37,10 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .expression("([^,]{2}),") // command .expression("([AV]),") // validity - .number("(xx)") // year - .number("(xx)") // month - .number("(xx),") // day - .number("(xx)") // hours - .number("(xx)") // minutes - .number("(xx),") // seconds - .number("(x)") - .number("(x{7}),") // latitude - .number("(x)") - .number("(x{7}),") // longitude + .number("(xx)(xx)(xx),") // date (yymmdd) + .number("(xx)(xx)(xx),") // time (hhmmss) + .number("(x)(x{7}),") // latitude + .number("(x)(x{7}),") // longitude .number("(x{4}),") // speed .number("(x{4}),") // course .number("(x{8}),") // status @@ -81,10 +74,7 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)) - .setTime(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS, 16)); if (BitUtil.check(parser.nextInt(16), 3)) { position.setLatitude(-parser.nextInt(16) / 600000.0); diff --git a/src/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/org/traccar/protocol/FifotrackProtocolDecoder.java index 995722fa7..321468a6b 100644 --- a/src/org/traccar/protocol/FifotrackProtocolDecoder.java +++ b/src/org/traccar/protocol/FifotrackProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -42,8 +41,8 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { .number("x+,") // index .expression("[^,]+,") // type .number("(d+)?,") // alarm - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("([AV]),") // validity .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude @@ -85,10 +84,7 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/FlextrackProtocolDecoder.java b/src/org/traccar/protocol/FlextrackProtocolDecoder.java index 9a9e849ca..2d7414f82 100644 --- a/src/org/traccar/protocol/FlextrackProtocolDecoder.java +++ b/src/org/traccar/protocol/FlextrackProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -45,8 +44,8 @@ public class FlextrackProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("(-?d+),") // index .text("UNITSTAT,") - .number("(dddd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd),") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("d+,") // node id .number("([NS])(d+).(d+.d+),") // latitude .number("([EW])(d+).(d+.d+),") // longitude @@ -110,10 +109,7 @@ public class FlextrackProtocolDecoder extends BaseProtocolDecoder { sendAcknowledgement(channel, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(true); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/FoxProtocolDecoder.java b/src/org/traccar/protocol/FoxProtocolDecoder.java index e48b13cb7..2b300a373 100644 --- a/src/org/traccar/protocol/FoxProtocolDecoder.java +++ b/src/org/traccar/protocol/FoxProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -36,8 +35,8 @@ public class FoxProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("(d+),") // status id .expression("([AV]),") // validity - .number("(dd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(dd)(dd.d+),") // latitude .expression("([NS]),") .number("(ddd)(dd.d+),") // longitude @@ -97,11 +96,7 @@ public class FoxProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java index a8995b8aa..50546782c 100644 --- a/src/org/traccar/protocol/FreedomProtocolDecoder.java +++ b/src/org/traccar/protocol/FreedomProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -35,8 +34,8 @@ public class FreedomProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("IMEI,") .number("(d+),") // imei - .number("(dddd)/(dd)/(dd), ") // date - .number("(dd):(dd):(dd), ") // time + .number("(dddd)/(dd)/(dd), ") // date (yyyy/dd/mm) + .number("(dd):(dd):(dd), ") // time (hh:mm:ss) .expression("([NS]), ") .number("Lat:(dd)(d+.d+), ") // latitude .expression("([EW]), ") @@ -65,10 +64,7 @@ public class FreedomProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java index daef6ea52..0b3c72a91 100644 --- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -50,8 +49,8 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder { .number("d*,") // gps accuracy .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .any() .compile(); @@ -89,10 +88,7 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); return position; } diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 74a734143..1fe1a3b5c 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -20,7 +20,6 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -30,6 +29,7 @@ import org.traccar.model.Position; import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; +import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; @@ -47,8 +47,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("([0-9A-Z]{2}xxxx),") // protocol version .number("(d{15}|x{14}),") // imei .any().text(",") - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(xxxx)") // counter .text("$").optional() .compile(); @@ -86,8 +86,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("[-+]dddd,") // timezone .expression("[01],") // daylight saving .groupEnd() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(xxxx)") // counter .text("$").optional() .compile(); @@ -100,8 +100,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .expression("([^,]*),") // device type .number("(xxxx),") // firmware version .number("(xxxx),") // hardware version - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(xxxx)") // counter .text("$").optional() .compile(); @@ -113,8 +113,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(-?d{1,5}.d)?,") // altitude .number("(-?d{1,3}.d{6})?,") // longitude .number("(-?d{1,2}.d{6})?,") // latitude - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .groupBegin() .number("(0ddd)?,") // mcc @@ -158,8 +158,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // odometer .expression(PATTERN_LOCATION.pattern()) .number("(d{1,7}.d)?,") // odometer - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -191,8 +191,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(?:d+.?d*|Inf|NaN)?,") // fuel consumption .number("(d+)?,") // fuel level .groupEnd() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -207,8 +207,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .expression(PATTERN_LOCATION.pattern()) .number("(d{5}:dd:dd)?,") // hour meter .number("(d{1,7}.d)?,") // odometer - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -225,8 +225,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .expression(PATTERN_LOCATION.pattern()) .number("(d+.d),") // odometer .text(",,,,") - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -240,8 +240,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // count .number("((?:x{12},-?d+,,,,)+),,,,") // wifi .number("(d{1,3}),") // battery - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -262,8 +262,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .or() .number("(d{1,7}.d)?,") // odometer .groupEnd() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -281,16 +281,16 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(-?d{1,5}.d)?,") // altitude .number("(-?d{1,3}.d{6})?,") // longitude .number("(-?d{1,2}.d{6})?,") // latitude - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(0ddd),") // mcc .number("(0ddd),") // mnc .number("(xxxx),") // lac .number("(xxxx),").optional(4) // cell .any() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -313,10 +313,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime()); position.setValid(false); position.set(Position.KEY_RESULT, "Command " + type + " accepted"); return position; @@ -360,11 +357,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_INPUT, parser.next()); position.set(Position.KEY_OUTPUT, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime()); position.set(Position.KEY_INDEX, parser.nextInt(16)); @@ -390,11 +383,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_VERSION_FW, parser.nextInt(16)); position.set(Position.KEY_VERSION_HW, parser.nextInt(16)); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime()); return position; } @@ -412,11 +401,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); - - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); } else { getLastLocation(position, null); } @@ -463,11 +448,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -537,11 +520,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { // workaround for wrong location time if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -569,11 +550,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -602,11 +581,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -678,11 +655,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { // workaround for wrong location time if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -724,10 +699,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); } if (parser.hasNext(4)) { @@ -736,11 +708,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java index 4c127a90b..a35cfa761 100644 --- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java +++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java @@ -212,12 +212,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.setValid(!parser.next().equals("1")); - - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setAltitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java index aff86ea7b..230a2df9a 100644 --- a/src/org/traccar/protocol/GnxProtocolDecoder.java +++ b/src/org/traccar/protocol/GnxProtocolDecoder.java @@ -18,13 +18,11 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.TimeZone; import java.util.regex.Pattern; public class GnxProtocolDecoder extends BaseProtocolDecoder { @@ -37,10 +35,10 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .number("d+,") // length .expression("([01]),") // history - .number("(dd)(dd)(dd),") // device time - .number("(dd)(dd)(dd),") // device date - .number("(dd)(dd)(dd),") // fix time - .number("(dd)(dd)(dd),") // fix date + .number("(dd)(dd)(dd),") // device time (hhmmss) + .number("(dd)(dd)(dd),") // device date (ddmmyy) + .number("(dd)(dd)(dd),") // fix time (hhmmss) + .number("(dd)(dd)(dd),") // fix date (ddmmyy) .number("(d),") // valid .number("(dd.d+),") // latitude .expression("([NS]),") @@ -95,17 +93,8 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ARCHIVE, true); } - DateBuilder dateBuilder; - - dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+5:30")) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setDeviceTime(dateBuilder.getDate()); - - dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+5:30")) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setFixTime(dateBuilder.getDate()); + position.setDeviceTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2, "GMT+5:30")); + position.setFixTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2, "GMT+5:30")); position.setValid(parser.nextInt() != 0); diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index 96f745917..a2a5edbd2 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -43,8 +43,8 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .text("*GS") // header .number("d+,") // protocol version .number("(d+),") // imei - .number("(dd)(dd)(dd)") // time - .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd)") // time (hhmmss) + .number("(dd)(dd)(dd),") // date (ddmmyy) .expression("(.*)#?") // data .compile(); @@ -242,10 +242,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { Date time = null; if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - time = dateBuilder.getDate(); + time = parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2); } List<Position> positions = new LinkedList<>(); diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java index 0c613eb2d..4a2f15ddc 100644 --- a/src/org/traccar/protocol/GotopProtocolDecoder.java +++ b/src/org/traccar/protocol/GotopProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -38,7 +37,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder { .expression("[^,]+,") // type .expression("([AV]),") // validity .number("DATE:(dd)(dd)(dd),") // date (yyddmm) - .number("TIME:(dd)(dd)(dd),") // time + .number("TIME:(dd)(dd)(dd),") // time (hhmmss) .number("LAT:(d+.d+)([NS]),") // latitude .number("LOT:(d+.d+)([EW]),") // longitude .text("Speed:").number("(d+.d+),") // speed @@ -67,10 +66,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 2f8fe4bba..3095be4f6 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -85,8 +85,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .text("imei:") .number("(d+),") // imei .expression("OBD,") // type - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d+),") // odometer .number("(d+.d+)?,") // fuel instant .number("(d+.d+)?,") // fuel average @@ -204,11 +204,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.set(Position.KEY_ODOMETER, parser.nextInt()); parser.next(); // instant fuel consumption diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index 47b02de94..a2454100f 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -35,7 +35,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_GPRMC = new PatternBuilder() .text("$GPRMC,") - .number("(dd)(dd)(dd).?(d+)?,") // time + .number("(dd)(dd)(dd).?(d+)?,") // time (hhmmss.ms) .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -60,7 +60,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd).?(d+)?,") // time + .number("(dd)(dd)(dd).?(d+)?,") // time (hhmmss.ms) .expression("([01])") // validity .any() .compile(); @@ -158,10 +158,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(parser.nextDouble()); position.setCourse(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMSms)); position.setValid(parser.next().equals("1")); diff --git a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java index 3f9b52cd1..a83e2e91e 100644 --- a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,8 +36,8 @@ public class GpsMarkerProtocolDecoder extends BaseProtocolDecoder { .number("d") // type .number("(?:xx)?") // index .number("(d{15})") // imei - .number("T(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd)?") // time + .number("T(dd)(dd)(dd)") // date (ddmmyy) + .number("(dd)(dd)(dd)?") // time (hhmmss) .expression("([NS])") .number("(dd)(dd)(dddd)") // latitude .expression("([EW])") @@ -71,10 +70,7 @@ public class GpsMarkerProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setValid(true); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN)); diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java index db26db820..dc8121ed3 100644 --- a/src/org/traccar/protocol/HaicomProtocolDecoder.java +++ b/src/org/traccar/protocol/HaicomProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,8 +36,8 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder { .text("$GPRS") .number("(d+),") // imei .expression("([^,]+),") // version - .number("(dd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d)") // flags .number("(dd)(d{5})") // latitude .number("(ddd)(d{5}),") // longitude @@ -74,10 +73,7 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_VERSION_FW, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); int flags = parser.nextInt(); diff --git a/src/org/traccar/protocol/HomtecsProtocolDecoder.java b/src/org/traccar/protocol/HomtecsProtocolDecoder.java index 78bf0a813..9b6356aa3 100644 --- a/src/org/traccar/protocol/HomtecsProtocolDecoder.java +++ b/src/org/traccar/protocol/HomtecsProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -34,8 +33,8 @@ public class HomtecsProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression("([^,]+),") // id - .number("(dd)(dd)(dd),") // date - .number("(dd)(dd)(dd).(d+),") // time + .number("(dd)(dd)(dd),") // date (yymmdd) + .number("(dd)(dd)(dd).(d+),") // time (hhmmss.ms) .number("(d+),") // satellites .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -64,11 +63,7 @@ public class HomtecsProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); - - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMSms)); position.setValid(true); position.set(Position.KEY_SATELLITES, parser.nextInt()); diff --git a/src/org/traccar/protocol/IdplProtocolDecoder.java b/src/org/traccar/protocol/IdplProtocolDecoder.java index 5e3638d8e..0f6aea9a8 100644 --- a/src/org/traccar/protocol/IdplProtocolDecoder.java +++ b/src/org/traccar/protocol/IdplProtocolDecoder.java @@ -22,7 +22,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.Protocol; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.Parser.CoordinateFormat; import org.traccar.helper.PatternBuilder; @@ -38,8 +37,8 @@ public class IdplProtocolDecoder extends BaseProtocolDecoder { .text("*ID") // start of frame .number("(d+),") // command code .number("(d+),") // imei - .number("(dd)(dd)(dd),") // current date - .number("(dd)(dd)(dd),") // current time + .number("(dd)(dd)(dd),") // current date (ddmmyy) + .number("(dd)(dd)(dd),") // current time (hhmmss) .expression("([A|V]),") // gps fix .number("(dd)(dd).?(d+),([NS]),") // latitude .number("(ddd)(dd).?(d+),([EW]),") // longitude @@ -81,10 +80,7 @@ public class IdplProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate(CoordinateFormat.DEG_MIN_MIN_HEM)); diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java index 70251fc51..0f69101aa 100644 --- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java +++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -35,8 +34,8 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression(".+,").optional() .number("(d+),") // identifier - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude .number("(d+.?d*),") // speed @@ -82,10 +81,7 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java index 60aadd025..d4b8c678b 100644 --- a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java +++ b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java @@ -19,7 +19,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
-import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.model.CellTower;
@@ -38,8 +37,8 @@ public class JpKorjarProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder()
.text("KORJAR.PL,")
.number("(d+),") // imei
- .number("(dd)(dd)(dd)") // date
- .number("(dd)(dd)(dd),") // time
+ .number("(dd)(dd)(dd)") // date (yymmdd)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
.number("(d+.d+)([NS]),") // latitude
.number("(d+.d+)([EW]),") // longitude
.number("(d+.d+),") // speed
@@ -70,10 +69,7 @@ public class JpKorjarProtocolDecoder extends BaseProtocolDecoder { }
position.setDeviceId(deviceSession.getDeviceId());
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
- .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
- position.setTime(dateBuilder.getDate());
+ position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index c8e41b03f..992baa6f6 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -162,7 +162,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { .expression("([NS]),") .expression("([AV]),") // validity .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d+),") // speed .number("(d+),") // course .number("(d+),") // power @@ -192,10 +192,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextCoordinate()); position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); position.setCourse(parser.nextDouble()); @@ -214,7 +211,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { .number("(Udd),") // type .number("d+,").optional() // alarm .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([TF]),") // validity .number("(d+.d+),([NS]),") // latitude .number("(d+.d+),([EW]),") // longitude @@ -250,10 +247,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setValid(parser.next().equals("T")); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); diff --git a/src/org/traccar/protocol/MaestroProtocolDecoder.java b/src/org/traccar/protocol/MaestroProtocolDecoder.java index f0b328cf9..654c9cadb 100644 --- a/src/org/traccar/protocol/MaestroProtocolDecoder.java +++ b/src/org/traccar/protocol/MaestroProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -43,8 +42,8 @@ public class MaestroProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // gsm .expression("([01]),") // starter .expression("([01]),") // ignition - .number("(dd)/(dd)/(dd),") // date - .number("(dd):(dd):(dd),") // time + .number("(dd)/(dd)/(dd),") // date (yy/mm/dd) + .number("(dd):(dd):(dd),") // time (hh:mm:ss) .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude .number("(d+.?d*),") // altitude @@ -82,10 +81,7 @@ public class MaestroProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_CHARGE, parser.nextInt() == 1); position.set(Position.KEY_IGNITION, parser.nextInt() == 1); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java index 39b651d7e..da82a66af 100644 --- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java +++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -38,8 +37,8 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder { .expression("[^,]*,[^,]*,") .expression("([^,]*),") // status .number("d+,d+,d+.?d*,") - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity .number("(dd)(dd.dddd),") // latitude .expression("([NS]),") @@ -69,10 +68,7 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_STATUS, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 60660adf6..ed8dcfd28 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -230,7 +230,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .expression("[^,]*,") // name .expression("([RS]),") .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity .number("(d+)(dd.d+),([NS]),") // latitude .number("(d+)(dd.d+),([EW]),") // longitude @@ -287,10 +287,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ARCHIVE, true); } - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index de739d0a4..e423a3df8 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -72,7 +72,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { .compile(); private static final Pattern PATTERN_RFID = new PatternBuilder() - .number("|(dd)(dd)(dd),") // time + .number("|(dd)(dd)(dd),") // time (hhmmss) .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(d+)(dd.d+),") // latitude .expression("([NS]),") @@ -268,10 +268,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { return null; } - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2)); position.setValid(true); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index a4a0d2d42..e97e44dac 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -20,7 +20,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -51,7 +50,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .number("(dd)(dd)(dd)") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("([AV]),") // validity .number("(d+),") // satellites .number("(d+),") // rssi @@ -107,10 +106,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setValid(parser.next().equals("A")); diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 94c67b616..46a11cd8f 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -35,8 +34,8 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN_FIX = new PatternBuilder() - .number("(d+)/(d+)/(d+),") // date - .number("(d+):(d+):(d+),") // time + .number("(d+)/(d+)/(d+),") // date (dd/mm/yy) + .number("(d+):(d+):(d+),") // time (hh:mm:ss) .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .compile(); @@ -78,11 +77,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { private void decodeFix(Position position, Parser parser) { - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); } diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java index 0b84603bd..8ad4ad314 100644 --- a/src/org/traccar/protocol/MtxProtocolDecoder.java +++ b/src/org/traccar/protocol/MtxProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -35,8 +34,8 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("#MTX,") .number("(d+),") // imei - .number("(dddd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd),") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .number("(d+.?d*),") // speed @@ -78,10 +77,7 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(true); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/PathAwayProtocolDecoder.java b/src/org/traccar/protocol/PathAwayProtocolDecoder.java index 036cfa445..142d3724b 100644 --- a/src/org/traccar/protocol/PathAwayProtocolDecoder.java +++ b/src/org/traccar/protocol/PathAwayProtocolDecoder.java @@ -25,7 +25,6 @@ import org.jboss.netty.handler.codec.http.HttpVersion; import org.jboss.netty.handler.codec.http.QueryStringDecoder; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -46,7 +45,7 @@ public class PathAwayProtocolDecoder extends BaseProtocolDecoder { .expression("[^,]*,") // icon .expression("[^,]*,") // color .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .number("(-?d+.?d*),") // altitude @@ -77,10 +76,7 @@ public class PathAwayProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setValid(true); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/PretraceProtocolDecoder.java b/src/org/traccar/protocol/PretraceProtocolDecoder.java index fa590c5a1..d3000df40 100644 --- a/src/org/traccar/protocol/PretraceProtocolDecoder.java +++ b/src/org/traccar/protocol/PretraceProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class PretraceProtocolDecoder extends BaseProtocolDecoder { .number("Uddd") // type .number("d") // gps type .expression("([AV])") // validity - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(dd)(dd.dddd)") // latitude .expression("([NS])") .number("(ddd)(dd.dddd)") // longitude @@ -78,10 +77,7 @@ public class PretraceProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/RaveonProtocolDecoder.java b/src/org/traccar/protocol/RaveonProtocolDecoder.java index 1fd3d4cd7..1fd5e6636 100644 --- a/src/org/traccar/protocol/RaveonProtocolDecoder.java +++ b/src/org/traccar/protocol/RaveonProtocolDecoder.java @@ -18,14 +18,12 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.Date; import java.util.regex.Pattern; public class RaveonProtocolDecoder extends BaseProtocolDecoder { @@ -40,7 +38,7 @@ public class RaveonProtocolDecoder extends BaseProtocolDecoder { .number("d+,") .number("(-?)(d+)(dd.d+),") // latitude .number("(-?)(d+)(dd.d+),") // longitude - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d),") // validity .number("(d+),") // satellites .number("(-?d+),") // altitude @@ -77,9 +75,7 @@ public class RaveonProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); - DateBuilder dateBuilder = new DateBuilder(new Date()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS)); position.setValid(parser.nextInt() != 0); diff --git a/src/org/traccar/protocol/SiwiProtocolDecoder.java b/src/org/traccar/protocol/SiwiProtocolDecoder.java index 78f32d01e..5a843760e 100644 --- a/src/org/traccar/protocol/SiwiProtocolDecoder.java +++ b/src/org/traccar/protocol/SiwiProtocolDecoder.java @@ -18,14 +18,12 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.TimeZone; import java.util.regex.Pattern; public class SiwiProtocolDecoder extends BaseProtocolDecoder { @@ -53,8 +51,8 @@ public class SiwiProtocolDecoder extends BaseProtocolDecoder { .number("(-?d+.d+),") // longitude .number("(-?d+),") // altitude .number("(d+),") // course - .number("(dd)(dd)(dd),") // time - .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd),") // time (hhmmss) + .number("(dd)(dd)(dd),") // date (ddmmyy) .any() .compile(); @@ -90,10 +88,7 @@ public class SiwiProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(parser.nextDouble()); position.setCourse(parser.nextInt()); - DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("IST")) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY4, "IST")); return position; } diff --git a/src/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/org/traccar/protocol/StarLinkProtocolDecoder.java index 46d8ee9cc..baa2cf823 100644 --- a/src/org/traccar/protocol/StarLinkProtocolDecoder.java +++ b/src/org/traccar/protocol/StarLinkProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.CellTower; @@ -78,17 +77,11 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_TYPE, parser.nextInt()); position.set(Position.KEY_INDEX, parser.nextInt()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setDeviceTime(dateBuilder.getDate()); + position.setDeviceTime(parser.nextDateTime()); position.set(Position.KEY_EVENT, parser.nextInt()); - dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setFixTime(dateBuilder.getDate()); + position.setFixTime(parser.nextDateTime()); position.setValid(true); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java index 9f7980032..387da7d4a 100644 --- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java +++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -85,10 +84,7 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); diff --git a/src/org/traccar/protocol/SupermateProtocolDecoder.java b/src/org/traccar/protocol/SupermateProtocolDecoder.java index 5e6615e9f..e5a04c5c4 100644 --- a/src/org/traccar/protocol/SupermateProtocolDecoder.java +++ b/src/org/traccar/protocol/SupermateProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -42,16 +41,10 @@ public class SupermateProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // command id .expression("([^,]{2}),") // command .expression("([AV]),") // validity - .number("(xx)") // year - .number("(xx)") // month - .number("(xx),") // day - .number("(xx)") // hours - .number("(xx)") // minutes - .number("(xx),") // seconds - .number("(x)") - .number("(x{7}),") // latitude - .number("(x)") - .number("(x{7}),") // longitude + .number("(xx)(xx)(xx),") // date (yymmdd) + .number("(xx)(xx)(xx),") // time (hhmmss) + .number("(x)(x{7}),") // latitude + .number("(x)(x{7}),") // longitude .number("(x{4}),") // speed .number("(x{4}),") // course .number("(x{12}),") // status @@ -86,10 +79,7 @@ public class SupermateProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)) - .setTime(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS, 16)); if (parser.nextInt(16) == 8) { position.setLatitude(-parser.nextInt(16) / 600000.0); diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java index cd50a99ff..e71c964b8 100644 --- a/src/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/T55ProtocolDecoder.java @@ -81,8 +81,8 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_TRCCR = new PatternBuilder() .text("$TRCCR,") - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd).?d*,") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd).?d*,") // time (hhmmss.ms) .expression("([AV]),") // validity .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude @@ -210,10 +210,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index c53538223..1f7df9565 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -50,8 +50,8 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { .or() .expression("(?:RGP|RCQ|RBR)") // type .number("(?:dd)?") - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // date (mmddyy) + .number("(dd)(dd)(dd)") // time (hhmmss) .groupEnd() .number("([-+]dd)(d{5})") // latitude .number("([-+]ddd)(d{5})") // longitude @@ -108,10 +108,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); } position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG)); diff --git a/src/org/traccar/protocol/TelicProtocolDecoder.java b/src/org/traccar/protocol/TelicProtocolDecoder.java index 1560efccc..d380c4227 100644 --- a/src/org/traccar/protocol/TelicProtocolDecoder.java +++ b/src/org/traccar/protocol/TelicProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // type .number("d{12},") // event time .number("d+,") - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (ddmmyy) + .number("(dd)(dd)(dd),") // time (hhmmss) .groupBegin() .number("(ddd)(dd)(dddd),") // longitude .number("(dd)(dd)(dddd),") // latitude @@ -82,10 +81,7 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, decodeAlarm(event)); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); if (parser.hasNext(6)) { position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN)); diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 9dc94678e..2eed0f15f 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -61,7 +61,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // device id .text("ZC20,") .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("d+,") // battery level .number("(d+),") // battery voltage .number("(d+),") // power voltage @@ -138,11 +138,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); int battery = parser.nextInt(); if (battery != 65535) { diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java index a0459a161..41c456e01 100644 --- a/src/org/traccar/protocol/TmgProtocolDecoder.java +++ b/src/org/traccar/protocol/TmgProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { .expression("(...),") // type .expression("[LH],") // history .number("(d+),") // imei - .number("(dd)(dd)(dddd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dddd),") // date (ddmmyyyy) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d),") // status .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -114,10 +113,7 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { break; } - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY4_HMS)); position.setValid(parser.nextInt() > 0); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java index 0be411246..fb9fb66fb 100644 --- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java +++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,7 +36,7 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder { .number("(d+)") // imei .any() .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .expression("([AV])") .number("(dd)(dd.dddd)([NS])") // latitude .number("(ddd)(dd.dddd)([EW])") // longitude @@ -63,10 +62,7 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index c7dc9e6c1..8c99df611 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -41,13 +41,13 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // imei .expression("(..)") // alarm .text("$GPRMC,") - .number("(dd)(dd)(dd).d+,") // time + .number("(dd)(dd)(dd).d+,") // time (hhmmss.ms) .expression("([AV]),") // validity .number("(d+)(dd.d+),([NS]),") // latitude .number("(d+)(dd.d+),([EW]),") // longitude .number("(d+.?d*)?,") // speed .number("(d+.?d*)?,") // course - .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd)") // date (ddmmyy) .expression("[^*]*").text("*") .number("xx|") // checksum .number("(d+.d+)|") // pdop @@ -75,7 +75,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // imei .expression("(..)") // alarm type .number("(dd)(dd)(dd)") // date (ddmmyy) - .number("(dd)(dd)(dd)|") // time + .number("(dd)(dd)(dd)|") // time (hhmmss) .expression("([AV])|") // validity .number("(d+)(dd.d+)|") // latitude .expression("([NS])|") @@ -104,7 +104,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // imei .expression("(..)") // alarm type .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(xxxx)") // io status .expression("[01]") // charging .number("(dd)") // battery @@ -135,7 +135,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // imei .number("(x{8})") // status .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(dd)") // battery .number("(dd)") // external power .number("(dddd)") // adc 1 @@ -269,10 +269,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext()) { position.set(Position.KEY_ALARM, decodeAlarm(Short.parseShort(parser.next(), 16))); } - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.set(Position.PREFIX_IO + 1, parser.next()); position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.1); @@ -298,10 +296,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { } else if (pattern == PATTERN4) { position.set(Position.KEY_STATUS, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.1); position.set(Position.KEY_POWER, parser.nextDouble()); diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java index 20f7d2968..02994f16b 100644 --- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -44,7 +43,7 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { .expression("([^,]+),") // id .expression("([AL]),") // validity .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([NS])") .number("(dd)(dd.d+)") // latitude .expression("([EW])") @@ -82,10 +81,7 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java index 1f867d5d1..70d9a51da 100644 --- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr900ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,7 +36,7 @@ public class Tr900ProtocolDecoder extends BaseProtocolDecoder { .number("d+,") // period .number("(d),") // fix .number("(dd)(dd)(dd),") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([EW])") .number("(ddd)(dd.d+),") // longitude .expression("([NS])") @@ -75,10 +74,7 @@ public class Tr900ProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.nextInt() == 1); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/TrakMateProtocolDecoder.java b/src/org/traccar/protocol/TrakMateProtocolDecoder.java index 95eef67c8..5cf0d07e7 100644 --- a/src/org/traccar/protocol/TrakMateProtocolDecoder.java +++ b/src/org/traccar/protocol/TrakMateProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -42,8 +41,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { .expression("([^ ]+)|") // uid .number("(d+.d+)|") // latitude .number("(d+.d+)|") // longitude - .number("(dd)(dd)(dd)|") // time - .number("(dd)(dd)(dd)|") // date + .number("(dd)(dd)(dd)|") // time (hhmmss) + .number("(dd)(dd)(dd)|") // date (ddmmyy) .number("(d+.d+)|") // software ver .number("(d+.d+)|") // Hardware ver .any() @@ -55,8 +54,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // seq .number("(d+.d+)|") // latitude .number("(d+.d+)|") // longitude - .number("(dd)(dd)(dd)|") // time - .number("(dd)(dd)(dd)|") // date + .number("(dd)(dd)(dd)|") // time (hhmmss) + .number("(dd)(dd)(dd)|") // date (ddmmyy) .number("(d+.d+)|") // speed .number("(d+.d+)|") // heading .number("(d+)|") // ignition @@ -81,8 +80,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // Alert status .number("(d+.d+)|") // latitude .number("(d+.d+)|") // longitude - .number("(dd)(dd)(dd)|") // time - .number("(dd)(dd)(dd)|") // date + .number("(dd)(dd)(dd)|") // time (hhmmss) + .number("(dd)(dd)(dd)|") // date (ddmmyy) .number("(d+.d+)|") // speed .number("(d+.d+)|") // heading .any() @@ -120,10 +119,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder(timeZone) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2)); position.set(Position.KEY_VERSION_FW, parser.next()); position.set(Position.KEY_VERSION_HW, parser.next()); @@ -154,10 +150,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder(timeZone) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2)); position.setSpeed(parser.nextDouble()); position.setCourse(parser.nextDouble()); @@ -186,10 +179,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder(timeZone) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY2)); position.setSpeed(parser.nextDouble()); position.setCourse(parser.nextDouble()); diff --git a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java index 32e20c272..301c87d88 100644 --- a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -49,8 +48,8 @@ public class Tt8850ProtocolDecoder extends BaseProtocolDecoder { .number("(-?d{1,5}.d)?,") // altitude .number("(-?d{1,3}.d{6}),") // longitude .number("(-?d{1,2}.d{6}),") // latitude - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(0ddd)?,") // mcc .number("(0ddd)?,") // mnc .number("(xxxx)?,") // lac @@ -87,10 +86,7 @@ public class Tt8850ProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); if (parser.hasNext(4)) { position.setNetwork(new Network( diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java index 0eac50817..b75b117d9 100644 --- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java +++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -37,8 +36,8 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder { .text("$1,") .expression("([^,]+),") // identifier .number("(d+),").optional() // imei - .number("(dd),(dd),(dd),") // date - .number("(dd),(dd),(dd),") // time + .number("(dd),(dd),(dd),") // date (dd,mm,yy) + .number("(dd),(dd),(dd),") // time (hh,mm,ss) .groupBegin() .number("(dd)(dd).?(d+)([NS]),") // latitude .number("(ddd)(dd).?(d+)([EW]),") // longitude @@ -91,10 +90,7 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); if (parser.hasNext(8)) { position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 4a48fe7b6..579b7c72b 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -50,7 +49,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_POSITION = new PatternBuilder() .text(",") .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity .number(" *(-?d+.d+),") // latitude .expression("([NS]),") @@ -182,10 +181,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index e3db1f8f0..6a2eb0228 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,7 +38,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("(dd)(dd)(dd);") // date (ddmmyy) - .number("(dd)(dd)(dd);") // time + .number("(dd)(dd)(dd);") // time (hhmmss) .number("(dd)(dd.d+);") // latitude .expression("([NS]);") .number("(ddd)(dd.d+);") // longitude @@ -85,10 +84,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY2_HMS)); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java index 491252bf6..fff4e9103 100644 --- a/src/org/traccar/protocol/WondexProtocolDecoder.java +++ b/src/org/traccar/protocol/WondexProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("[^d]*") // deader .number("(d+),") // device identifier - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude .number("(d+),") // speed @@ -98,10 +97,7 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java index 633479350..c4d005678 100644 --- a/src/org/traccar/protocol/XirgoProtocolDecoder.java +++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -59,8 +58,8 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { .text("$$") .number("(d+),") // imei .number("(d+),") // event - .number("(dddd)/(dd)/(dd),") // date - .number("(dd):(dd):(dd),") // time + .number("(dddd)/(dd)/(dd),") // date (yyyy/mm/dd) + .number("(dd):(dd):(dd),") // time (hh:mm:ss) .number("(-?d+.?d*),") // latitude .number("(-?d+.?d*),") // longitude .number("(-?d+.?d*),") // altitude @@ -120,10 +119,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_EVENT, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java index 40231a06d..73295f9c2 100644 --- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -38,7 +37,7 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder { .text("TK,") .number("(d+),") // imei .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("([+-]d+.d+),") // latitude .number("([+-]d+.d+),") // longitude .number("(d+),") // speed @@ -75,10 +74,7 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java index 85f1264a8..17cbd376c 100644 --- a/src/org/traccar/protocol/YwtProtocolDecoder.java +++ b/src/org/traccar/protocol/YwtProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,7 +36,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { .number("(d+):") // unit identifier .number("d+,") // subtype .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([EW])") .number("(ddd.d{6}),") // longitude .expression("([NS])") @@ -88,10 +87,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.Y2MD_HMS)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG)); |