aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-08-05 14:09:51 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-08-05 14:09:51 +1200
commitc790266c87a165d1fc5b2ef3b13a07ec692f5f54 (patch)
treead55faed369a654a69461f666eeea993c3984d95
parentd96efab59ac88c4a6f481154afbd8e071dcee219 (diff)
downloadtrackermap-server-c790266c87a165d1fc5b2ef3b13a07ec692f5f54.tar.gz
trackermap-server-c790266c87a165d1fc5b2ef3b13a07ec692f5f54.tar.bz2
trackermap-server-c790266c87a165d1fc5b2ef3b13a07ec692f5f54.zip
Fix date and time formatting issues
-rw-r--r--pom.xml5
-rw-r--r--src/org/traccar/database/DataManager.java6
-rw-r--r--src/org/traccar/web/JsonConverter.java13
-rw-r--r--test/org/traccar/web/JsonConverterTest.java2
-rw-r--r--web/app/view/report/ReportController.js4
5 files changed, 20 insertions, 10 deletions
diff --git a/pom.xml b/pom.xml
index 125a7eeb1..50a88a984 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,6 +22,11 @@
<version>1.2.17</version>
</dependency>
<dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>2.8.1</version>
+ </dependency>
+ <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.187</version>
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 3cfeadae4..0b8cff03a 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -210,17 +210,17 @@ public class DataManager implements IdentityManager {
Position position = new Position();
position.setDeviceId(device.getId());
- position.setTime(JsonConverter.parseDate("2015-05-22T12:00:01"));
+ position.setTime(JsonConverter.parseDate("2015-05-22T12:00:01.000Z"));
position.setLatitude(-36.8785803);
position.setLongitude(174.7281713);
addPosition(position);
- position.setTime(JsonConverter.parseDate("2015-05-22T12:00:02"));
+ position.setTime(JsonConverter.parseDate("2015-05-22T12:00:02.000Z"));
position.setLatitude(-36.8870932);
position.setLongitude(174.7473116);
addPosition(position);
- position.setTime(JsonConverter.parseDate("2015-05-22T12:00:03"));
+ position.setTime(JsonConverter.parseDate("2015-05-22T12:00:03.000Z"));
position.setLatitude(-36.8932371);
position.setLongitude(174.7743053);
addPosition(position);
diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java
index cdcd492b8..a78821d1f 100644
--- a/src/org/traccar/web/JsonConverter.java
+++ b/src/org/traccar/web/JsonConverter.java
@@ -32,15 +32,20 @@ import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonReader;
import javax.json.JsonValue;
+
+import org.apache.log4j.helpers.ISO8601DateFormat;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
import org.traccar.model.Factory;
import org.traccar.model.MiscFormatter;
public class JsonConverter {
- private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+ private static final DateTimeFormatter dateFormat = ISODateTimeFormat.dateTime();
public static Date parseDate(String value) throws ParseException {
- return dateFormat.parse(value);
+ return dateFormat.parseDateTime(value).toDate();
}
public static <T extends Factory> T objectFromJson(Reader reader, T prototype) throws ParseException {
@@ -74,7 +79,7 @@ public class JsonConverter {
} else if (parameterType.equals(String.class)) {
method.invoke(object, json.getString(name));
} else if (parameterType.equals(Date.class)) {
- method.invoke(object, dateFormat.parse(json.getString(name)));
+ method.invoke(object, dateFormat.parseDateTime(json.getString(name)).toDate());
} else if (parameterType.equals(Map.class)) {
method.invoke(object, MiscFormatter.fromJson(json.getJsonObject(name)));
}
@@ -115,7 +120,7 @@ public class JsonConverter {
} else if (method.getReturnType().equals(Date.class)) {
Date value = (Date) method.invoke(object);
if (value != null) {
- json.add(name, dateFormat.format(value));
+ json.add(name, dateFormat.print(new DateTime(value)));
}
} else if (method.getReturnType().equals(Map.class)) {
json.add(name, MiscFormatter.toJson((Map) method.invoke(object)));
diff --git a/test/org/traccar/web/JsonConverterTest.java b/test/org/traccar/web/JsonConverterTest.java
index 2b08c4f2c..2e869ae01 100644
--- a/test/org/traccar/web/JsonConverterTest.java
+++ b/test/org/traccar/web/JsonConverterTest.java
@@ -19,7 +19,7 @@ public class JsonConverterTest {
"\"int\": 42, " +
"\"double\": 41.99, " +
"\"string\": \"discworld\", " +
- "\"date\":\"2015-07-09T19:02:17+0000\"" +
+ "\"date\":\"2015-07-09T19:02:17.000Z\"" +
"}"),
new Primitives());
diff --git a/web/app/view/report/ReportController.js b/web/app/view/report/ReportController.js
index ffc75dc1c..64c89867d 100644
--- a/web/app/view/report/ReportController.js
+++ b/web/app/view/report/ReportController.js
@@ -49,8 +49,8 @@ Ext.define('Traccar.view.report.ReportController', {
store.load({
params:{
deviceId: deviceId,
- from: from,
- to: to
+ from: from.toISOString(),
+ to: to.toISOString()
},
scope: this,
callback: function() {