aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-03-13 17:52:28 +0500
committerAbyss777 <abyss@fox5.ru>2017-03-13 17:52:28 +0500
commit2309d53f52f25efe00f2195a58c448506a2605ab (patch)
tree9fdddd2384e4e331c1642f919d3db4fb1621cccb /src/org
parent633bed5cd14c16d53c7b84ed2c6586915467e1a8 (diff)
downloadtrackermap-server-2309d53f52f25efe00f2195a58c448506a2605ab.tar.gz
trackermap-server-2309d53f52f25efe00f2195a58c448506a2605ab.tar.bz2
trackermap-server-2309d53f52f25efe00f2195a58c448506a2605ab.zip
- Add timezone field to User and Server model
- Pass Velocity DateTool to templates - Adjusted templates to use timezone
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/model/Server.java15
-rw-r--r--src/org/traccar/model/User.java14
-rw-r--r--src/org/traccar/notification/NotificationFormatter.java5
-rw-r--r--src/org/traccar/reports/ReportUtils.java9
4 files changed, 43 insertions, 0 deletions
diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java
index b588a4de0..db3f021a9 100644
--- a/src/org/traccar/model/Server.java
+++ b/src/org/traccar/model/Server.java
@@ -15,6 +15,8 @@
*/
package org.traccar.model;
+import java.util.TimeZone;
+
import org.traccar.helper.Log;
public class Server extends Extensible {
@@ -166,4 +168,17 @@ public class Server extends Extensible {
this.coordinateFormat = coordinateFormat;
}
+ private String timezone;
+
+ public void setTimezone(String timezone) {
+ if (timezone != null) {
+ this.timezone = TimeZone.getTimeZone(timezone).getID();
+ } else {
+ this.timezone = null;
+ }
+ }
+
+ public String getTimezone() {
+ return timezone;
+ }
}
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
index 274f2b2a2..71bb563a8 100644
--- a/src/org/traccar/model/User.java
+++ b/src/org/traccar/model/User.java
@@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import org.traccar.helper.Hashing;
import java.util.Date;
+import java.util.TimeZone;
public class User extends Extensible {
@@ -265,4 +266,17 @@ public class User extends Extensible {
return Hashing.validatePassword(password, hashedPassword, salt);
}
+ private String timezone;
+
+ public void setTimezone(String timezone) {
+ if (timezone != null) {
+ this.timezone = TimeZone.getTimeZone(timezone).getID();
+ } else {
+ this.timezone = null;
+ }
+ }
+
+ public String getTimezone() {
+ return timezone;
+ }
}
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java
index cec238548..eae2681c9 100644
--- a/src/org/traccar/notification/NotificationFormatter.java
+++ b/src/org/traccar/notification/NotificationFormatter.java
@@ -18,10 +18,12 @@ package org.traccar.notification;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
+import java.util.Locale;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.tools.generic.DateTool;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Device;
@@ -48,6 +50,9 @@ public final class NotificationFormatter {
velocityContext.put("geofence", Context.getGeofenceManager().getGeofence(event.getGeofenceId()));
}
velocityContext.put("webUrl", Context.getVelocityEngine().getProperty("web.url"));
+ velocityContext.put("dateTool", new DateTool());
+ velocityContext.put("timezone", ReportUtils.getTimezone(userId));
+ velocityContext.put("locale", Locale.getDefault());
return velocityContext;
}
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 1402e10d4..968fb357b 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -24,6 +24,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.TimeZone;
public final class ReportUtils {
@@ -46,6 +47,14 @@ public final class ReportUtils {
return unit != null ? unit : "kn";
}
+ public static TimeZone getTimezone(long userId) {
+ String timezone = Context.getPermissionsManager().getUser(userId).getTimezone();
+ if (timezone == null) {
+ timezone = Context.getPermissionsManager().getServer().getTimezone();
+ }
+ return timezone != null ? TimeZone.getTimeZone(timezone) : TimeZone.getDefault();
+ }
+
public static Collection<Long> getDeviceList(Collection<Long> deviceIds, Collection<Long> groupIds) {
Collection<Long> result = new ArrayList<>();
result.addAll(deviceIds);