diff options
Diffstat (limited to 'src/org/traccar/web/client/FormatterUtil.java')
-rw-r--r-- | src/org/traccar/web/client/FormatterUtil.java | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/org/traccar/web/client/FormatterUtil.java b/src/org/traccar/web/client/FormatterUtil.java index f5c7d3e1..36c24dcb 100644 --- a/src/org/traccar/web/client/FormatterUtil.java +++ b/src/org/traccar/web/client/FormatterUtil.java @@ -1,8 +1,8 @@ package org.traccar.web.client; -import java.util.Date; - +import com.google.gwt.i18n.client.CurrencyList; import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.NumberFormat; public class FormatterUtil { @@ -10,8 +10,33 @@ public class FormatterUtil { return DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss"); } - public String formatTime(Date time) { - return getTimeFormat().format(time); + private class SpeedNumberFormat extends NumberFormat { + + private final String unit; + private final double factor; + + public SpeedNumberFormat(String unit, double factor) { + super("0.##", CurrencyList.get().getDefault(), true); + this.unit = unit; + this.factor = factor; + } + + @Override + public String format(double number) { + return super.format(number * factor) + " " + unit; + } + + } + + public NumberFormat getSpeedFormat() { + switch (ApplicationContext.getInstance().getUserSettings().getSpeedUnit()) { + case kilometersPerHour: + return new SpeedNumberFormat("km/h", 1.852); + case milesPerHour: + return new SpeedNumberFormat("mph", 1.150779); + default: + return new SpeedNumberFormat("kn", 1); + } } } |