commit e18b1cd7bb0cc6a6c6cb29dc00b37daa6a4c3aa2 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Apr 1 12:45:31 2020 +0200
Set default locale US and default time zone UTC.
Part of #33655. --- CHANGELOG.md | 2 ++ src/build | 2 +- src/main/java/org/torproject/metrics/onionoo/cron/Main.java | 4 ++++ .../java/org/torproject/metrics/onionoo/docs/DateTimeHelper.java | 2 -- src/main/java/org/torproject/metrics/onionoo/docs/WeightsStatus.java | 3 +-- src/main/java/org/torproject/metrics/onionoo/server/NodeIndex.java | 3 --- .../org/torproject/metrics/onionoo/server/PerformanceMetrics.java | 2 -- src/main/java/org/torproject/metrics/onionoo/server/ServerMain.java | 5 +++++ 8 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md index f8666fd..4637ad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@
* Minor changes - Simplify logging configuration. + - Set default locale `US` and default time zone `UTC` at the + beginning of the execution.
# Changes in version 8.0-1.25.0 - 2020-02-20 diff --git a/src/build b/src/build index fd85646..b5e1a2d 160000 --- a/src/build +++ b/src/build @@ -1 +1 @@ -Subproject commit fd856466bcb260f53ef69a24c102d0e49d171cc3 +Subproject commit b5e1a2d7b29e58cc0645f068a1ebf4377bf9d8b8 diff --git a/src/main/java/org/torproject/metrics/onionoo/cron/Main.java b/src/main/java/org/torproject/metrics/onionoo/cron/Main.java index 9f3c3c6..9470ca9 100644 --- a/src/main/java/org/torproject/metrics/onionoo/cron/Main.java +++ b/src/main/java/org/torproject/metrics/onionoo/cron/Main.java @@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.util.Calendar; +import java.util.Locale; +import java.util.TimeZone; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -29,6 +31,8 @@ public class Main implements Runnable { /** Executes a single update run or partial update run, or initiates * hourly executions, depending on the given command-line arguments. */ public static void main(String[] args) { + Locale.setDefault(Locale.US); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Main main = new Main(); main.parseArgsOrExit(args); main.runOrScheduleExecutions(); diff --git a/src/main/java/org/torproject/metrics/onionoo/docs/DateTimeHelper.java b/src/main/java/org/torproject/metrics/onionoo/docs/DateTimeHelper.java index b0bda36..9a8745e 100644 --- a/src/main/java/org/torproject/metrics/onionoo/docs/DateTimeHelper.java +++ b/src/main/java/org/torproject/metrics/onionoo/docs/DateTimeHelper.java @@ -11,7 +11,6 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; -import java.util.TimeZone;
public class DateTimeHelper {
@@ -80,7 +79,6 @@ public class DateTimeHelper { if (!threadDateFormats.containsKey(format)) { DateFormat dateFormat = new SimpleDateFormat(format); dateFormat.setLenient(false); - dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); threadDateFormats.put(format, dateFormat); } return threadDateFormats.get(format); diff --git a/src/main/java/org/torproject/metrics/onionoo/docs/WeightsStatus.java b/src/main/java/org/torproject/metrics/onionoo/docs/WeightsStatus.java index b9a8265..c61551c 100644 --- a/src/main/java/org/torproject/metrics/onionoo/docs/WeightsStatus.java +++ b/src/main/java/org/torproject/metrics/onionoo/docs/WeightsStatus.java @@ -7,7 +7,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory;
import java.util.Comparator; -import java.util.Locale; import java.util.Map; import java.util.Scanner; import java.util.SortedMap; @@ -207,7 +206,7 @@ public class WeightsStatus extends Document { for (int i = 0; i < weights.length; i++) { sb.append(" "); if (i != 0 && i != 5 && !Double.valueOf(weights[i]).isNaN()) { - sb.append(String.format(Locale.US, "%.12f", weights[i])); + sb.append(String.format("%.12f", weights[i])); } } sb.append("\n"); diff --git a/src/main/java/org/torproject/metrics/onionoo/server/NodeIndex.java b/src/main/java/org/torproject/metrics/onionoo/server/NodeIndex.java index dc101a1..30b366c 100644 --- a/src/main/java/org/torproject/metrics/onionoo/server/NodeIndex.java +++ b/src/main/java/org/torproject/metrics/onionoo/server/NodeIndex.java @@ -10,7 +10,6 @@ import java.text.SimpleDateFormat; import java.util.Map; import java.util.Set; import java.util.SortedMap; -import java.util.TimeZone;
class NodeIndex {
@@ -19,7 +18,6 @@ class NodeIndex { public void setRelaysPublishedMillis(long relaysPublishedMillis) { SimpleDateFormat dateTimeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); - dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC")); this.relaysPublishedString = dateTimeFormat.format(relaysPublishedMillis); } @@ -33,7 +31,6 @@ class NodeIndex { public void setBridgesPublishedMillis(long bridgesPublishedMillis) { SimpleDateFormat dateTimeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); - dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC")); this.bridgesPublishedString = dateTimeFormat.format(bridgesPublishedMillis); } diff --git a/src/main/java/org/torproject/metrics/onionoo/server/PerformanceMetrics.java b/src/main/java/org/torproject/metrics/onionoo/server/PerformanceMetrics.java index 22a5573..0e0673f 100644 --- a/src/main/java/org/torproject/metrics/onionoo/server/PerformanceMetrics.java +++ b/src/main/java/org/torproject/metrics/onionoo/server/PerformanceMetrics.java @@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat; import java.util.Collection; -import java.util.TimeZone;
public class PerformanceMetrics {
@@ -64,7 +63,6 @@ public class PerformanceMetrics { > LOG_INTERVAL_MILLIS) { SimpleDateFormat dateTimeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); - dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC")); logger.info("Request statistics ({}, {} s):", dateTimeFormat.format(lastLoggedMillis + LOG_INTERVAL_MILLIS), LOG_INTERVAL_SECONDS); diff --git a/src/main/java/org/torproject/metrics/onionoo/server/ServerMain.java b/src/main/java/org/torproject/metrics/onionoo/server/ServerMain.java index 0cab37a..a8c1ba0 100644 --- a/src/main/java/org/torproject/metrics/onionoo/server/ServerMain.java +++ b/src/main/java/org/torproject/metrics/onionoo/server/ServerMain.java @@ -9,6 +9,9 @@ import org.eclipse.jetty.xml.XmlConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
+import java.util.Locale; +import java.util.TimeZone; + public class ServerMain {
private static final Logger logger = LoggerFactory.getLogger( @@ -16,6 +19,8 @@ public class ServerMain {
/** Starts the web server listening for incoming client connections. */ public static void main(String[] args) { + Locale.setDefault(Locale.US); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); try { Resource onionooXml = Resource.newSystemResource("jetty.xml"); logger.info("Reading configuration from '{}'.", onionooXml);
tor-commits@lists.torproject.org