aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-06-04 19:42:56 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2014-06-04 19:42:56 +1200
commitffc1755cca2476dc9a4bb430c968207657997222 (patch)
treed67688887bc86f003e8e0ab2ed797952bf19df1a
parent59e4bf0a8581a168b0f355551244dc45128cba7c (diff)
downloadtrackermap-server-ffc1755cca2476dc9a4bb430c968207657997222.tar.gz
trackermap-server-ffc1755cca2476dc9a4bb430c968207657997222.tar.bz2
trackermap-server-ffc1755cca2476dc9a4bb430c968207657997222.zip
Support alternative time format
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java9
-rw-r--r--test/org/traccar/protocol/OsmAndProtocolDecoderTest.java3
2 files changed, 11 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index 5cb6e6455..560f3224f 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -16,6 +16,8 @@
package org.traccar.protocol;
import java.nio.charset.Charset;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -70,7 +72,12 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
// Decode position
position.setValid(true);
if (params.containsKey("timestamp")) {
- position.setTime(new Date(Long.valueOf(params.get("timestamp").get(0)) * 1000));
+ try {
+ position.setTime(new Date(Long.valueOf(params.get("timestamp").get(0)) * 1000));
+ } catch (NumberFormatException error) {
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ position.setTime(dateFormat.parse(params.get("timestamp").get(0)));
+ }
} else {
position.setTime(new Date());
}
diff --git a/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java b/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java
index 72a19a55e..7aed1b5ed 100644
--- a/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java
@@ -16,6 +16,9 @@ public class OsmAndProtocolDecoderTest {
decoder.setDataManager(new TestDataManager());
verify(decoder.decode(null, null, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
+ "/?lat=49.60688&lon=6.15788&timestamp=2014-06-04+09%3A10%3A11&altitude=384.7&speed=0.0&id=353861053849681")));
+
+ verify(decoder.decode(null, null, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
"/?id=123456&timestamp=1377177267&lat=60.0&lon=30.0&speed=0.0&bearing=0.0&altitude=0&hdop=0.0")));
verify(decoder.decode(null, null, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,