aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-09-22 11:40:02 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-09-22 11:40:02 +1200
commita7296d99876000e65bef9b9df708f57ebabbe894 (patch)
tree27175047d4b59b55c3e59d5bfafff96255570202
parent02d5eb894a4c5f5fe8270303af2c8ba4be03b530 (diff)
downloadtraccar-server-a7296d99876000e65bef9b9df708f57ebabbe894.tar.gz
traccar-server-a7296d99876000e65bef9b9df708f57ebabbe894.tar.bz2
traccar-server-a7296d99876000e65bef9b9df708f57ebabbe894.zip
Fix date formatting (fix #4063)
-rw-r--r--src/org/traccar/Context.java4
-rw-r--r--src/org/traccar/database/StatisticsManager.java3
-rw-r--r--src/org/traccar/helper/DateUtil.java5
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java4
-rw-r--r--src/org/traccar/web/CsvBuilder.java3
-rw-r--r--src/org/traccar/web/GpxBuilder.java5
6 files changed, 14 insertions, 10 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index f7bc18d1d..334503640 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -20,6 +20,8 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import java.util.Properties;
import com.fasterxml.jackson.datatype.jsr353.JSR353Module;
@@ -92,6 +94,8 @@ public final class Context {
private static final Logger LOGGER = LoggerFactory.getLogger(Context.class);
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+ public static final DateTimeFormatter DATE_FORMATTER =
+ DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.systemDefault());
private Context() {
}
diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java
index c2011a878..735c1f1a7 100644
--- a/src/org/traccar/database/StatisticsManager.java
+++ b/src/org/traccar/database/StatisticsManager.java
@@ -23,7 +23,6 @@ import org.traccar.model.Statistics;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
import java.sql.SQLException;
-import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
@@ -72,7 +71,7 @@ public class StatisticsManager {
String url = Context.getConfig().getString("server.statistics");
if (url != null) {
- String time = DateTimeFormatter.ISO_DATE_TIME.format(statistics.getCaptureTime().toInstant());
+ String time = Context.DATE_FORMATTER.format(statistics.getCaptureTime().toInstant());
Form form = new Form();
form.param("version", Context.getAppVersion());
diff --git a/src/org/traccar/helper/DateUtil.java b/src/org/traccar/helper/DateUtil.java
index 458c74609..e09ac6d0e 100644
--- a/src/org/traccar/helper/DateUtil.java
+++ b/src/org/traccar/helper/DateUtil.java
@@ -15,8 +15,9 @@
*/
package org.traccar.helper;
+import org.traccar.Context;
+
import java.time.Instant;
-import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
@@ -58,7 +59,7 @@ public final class DateUtil {
}
public static Date parseDate(String value) {
- return Date.from(Instant.from(DateTimeFormatter.ISO_DATE_TIME.parse(value)));
+ return Date.from(Instant.from(Context.DATE_FORMATTER.parse(value)));
}
}
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index 4d6a0d259..ab2bc7c7d 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -20,6 +20,7 @@ import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.QueryStringDecoder;
import org.traccar.BaseHttpProtocolDecoder;
+import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
@@ -31,7 +32,6 @@ import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
-import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -83,7 +83,7 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder {
} catch (NumberFormatException error) {
if (value.contains("T")) {
position.setTime(
- Date.from(Instant.from(DateTimeFormatter.ISO_DATE_TIME.parse(value))));
+ Date.from(Instant.from(Context.DATE_FORMATTER.parse(value))));
} else {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
position.setTime(dateFormat.parse(value));
diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java
index f7455b528..cd4efea9f 100644
--- a/src/org/traccar/web/CsvBuilder.java
+++ b/src/org/traccar/web/CsvBuilder.java
@@ -19,7 +19,6 @@ package org.traccar.web;
import java.beans.Introspector;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
@@ -91,7 +90,7 @@ public class CsvBuilder {
addSeparator();
} else if (method.getReturnType().equals(Date.class)) {
Date value = (Date) method.invoke(object);
- builder.append(DateTimeFormatter.ISO_DATE_TIME.format(value.toInstant()));
+ builder.append(Context.DATE_FORMATTER.format(value.toInstant()));
addSeparator();
} else if (method.getReturnType().equals(Map.class)) {
Map value = (Map) method.invoke(object);
diff --git a/src/org/traccar/web/GpxBuilder.java b/src/org/traccar/web/GpxBuilder.java
index a4daf154e..41f406eb7 100644
--- a/src/org/traccar/web/GpxBuilder.java
+++ b/src/org/traccar/web/GpxBuilder.java
@@ -16,8 +16,9 @@
*/
package org.traccar.web;
-import java.time.format.DateTimeFormatter;
import java.util.Collection;
+
+import org.traccar.Context;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
@@ -50,7 +51,7 @@ public class GpxBuilder {
public void addPosition(Position position) {
builder.append(String.format(POINT, position.getLatitude(), position.getLongitude(),
- DateTimeFormatter.ISO_DATE_TIME.format(position.getFixTime().toInstant()), position.getAltitude(),
+ Context.DATE_FORMATTER.format(position.getFixTime().toInstant()), position.getAltitude(),
position.getCourse(), UnitsConverter.mpsFromKnots(position.getSpeed())));
}