[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-web/master] Set default locale US and default time zone UTC.



commit 9844bc523c98965f1d626dd8f7f892fef09aabe3
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Wed Apr 1 12:45:37 2020 +0200

    Set default locale US and default time zone UTC.
    
    Part of these changes have already been made in earlier commits as
    part of #24532. This commit makes remaining changes as part of #33655.
---
 src/build                                                              | 2 +-
 src/main/java/org/torproject/metrics/stats/advbwdist/Main.java         | 3 ---
 src/main/java/org/torproject/metrics/stats/connbidirect/Main.java      | 3 ---
 src/main/java/org/torproject/metrics/stats/hidserv/DateTimeHelper.java | 2 --
 src/main/java/org/torproject/metrics/web/GraphParameterChecker.java    | 2 --
 src/main/java/org/torproject/metrics/web/GraphServlet.java             | 2 --
 src/main/java/org/torproject/metrics/web/NewsServlet.java              | 3 +--
 src/main/java/org/torproject/metrics/web/ServerMain.java               | 2 ++
 src/main/java/org/torproject/metrics/web/TableParameterChecker.java    | 2 --
 src/main/java/org/torproject/metrics/web/TableServlet.java             | 2 --
 src/main/java/org/torproject/metrics/web/UpdateNews.java               | 2 ++
 11 files changed, 6 insertions(+), 19 deletions(-)

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/stats/advbwdist/Main.java b/src/main/java/org/torproject/metrics/stats/advbwdist/Main.java
index 1e6bd0e..cda9da1 100644
--- a/src/main/java/org/torproject/metrics/stats/advbwdist/Main.java
+++ b/src/main/java/org/torproject/metrics/stats/advbwdist/Main.java
@@ -27,7 +27,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
-import java.util.TimeZone;
 import java.util.TreeMap;
 
 public class Main {
@@ -72,7 +71,6 @@ public class Main {
     }
     SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
         "yyyy-MM-dd HH:mm:ss");
-    dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
     for (Descriptor descriptor : descriptorReader.readDescriptors(new File(
         org.torproject.metrics.stats.main.Main.descriptorsDir,
         "recent/relay-descriptors/consensuses"))) {
@@ -150,7 +148,6 @@ public class Main {
 
     /* Aggregate statistics. */
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
     String today = dateFormat.format(new Date());
     SortedMap<String, List<Long>> preAggregatedValues = new TreeMap<>();
     try (BufferedReader br = new BufferedReader(new FileReader(resultsFile))) {
diff --git a/src/main/java/org/torproject/metrics/stats/connbidirect/Main.java b/src/main/java/org/torproject/metrics/stats/connbidirect/Main.java
index 2abf202..be10239 100644
--- a/src/main/java/org/torproject/metrics/stats/connbidirect/Main.java
+++ b/src/main/java/org/torproject/metrics/stats/connbidirect/Main.java
@@ -28,7 +28,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.SortedSet;
-import java.util.TimeZone;
 import java.util.TreeMap;
 import java.util.TreeSet;
 
@@ -184,7 +183,6 @@ public class Main {
           + "proceeding.  To fix this, you'll have to re-import "
           + "statistics for the following dates:");
       DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-      dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
       for (long conflictingDate : conflictingDates) {
         sb.append("\n ")
             .append(dateFormat.format(conflictingDate * ONE_DAY_IN_MILLIS));
@@ -436,7 +434,6 @@ public class Main {
       SortedMap<String, Short> aggregateStats,
       SortedSet<RawStat> rawStats) {
     DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
     String yesterday = dateFormat.format(System.currentTimeMillis()
         - ONE_DAY_IN_MILLIS);
     SortedMap<String, List<Short>> fractionsByDateAndDirection
diff --git a/src/main/java/org/torproject/metrics/stats/hidserv/DateTimeHelper.java b/src/main/java/org/torproject/metrics/stats/hidserv/DateTimeHelper.java
index 2fa866f..064d732 100644
--- a/src/main/java/org/torproject/metrics/stats/hidserv/DateTimeHelper.java
+++ b/src/main/java/org/torproject/metrics/stats/hidserv/DateTimeHelper.java
@@ -8,7 +8,6 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.TimeZone;
 
 /** Utility class to format and parse dates and timestamps. */
 public class DateTimeHelper {
@@ -49,7 +48,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/web/GraphParameterChecker.java b/src/main/java/org/torproject/metrics/web/GraphParameterChecker.java
index 236a190..0534684 100644
--- a/src/main/java/org/torproject/metrics/web/GraphParameterChecker.java
+++ b/src/main/java/org/torproject/metrics/web/GraphParameterChecker.java
@@ -11,7 +11,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TimeZone;
 
 /**
  * Checks request parameters passed to graph-generating servlets.
@@ -45,7 +44,6 @@ public class GraphParameterChecker {
    */
   public GraphParameterChecker() {
     this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-    this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
     this.availableGraphs = new HashMap<>();
     for (Metric metric : ContentProvider.getInstance().getMetricsList()) {
       if ("Graph".equals(metric.getType())) {
diff --git a/src/main/java/org/torproject/metrics/web/GraphServlet.java b/src/main/java/org/torproject/metrics/web/GraphServlet.java
index 507ae3b..d080f9e 100644
--- a/src/main/java/org/torproject/metrics/web/GraphServlet.java
+++ b/src/main/java/org/torproject/metrics/web/GraphServlet.java
@@ -13,7 +13,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TimeZone;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -145,7 +144,6 @@ public class GraphServlet extends MetricServlet {
     request.setAttribute("description",
         this.descriptions.get(requestedId));
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
     Date defaultEndDate = new Date();
     Date defaultStartDate = new Date(defaultEndDate.getTime()
         - 90L * 24L * 60L * 60L * 1000L);
diff --git a/src/main/java/org/torproject/metrics/web/NewsServlet.java b/src/main/java/org/torproject/metrics/web/NewsServlet.java
index b5dddc1..4a9d313 100644
--- a/src/main/java/org/torproject/metrics/web/NewsServlet.java
+++ b/src/main/java/org/torproject/metrics/web/NewsServlet.java
@@ -9,7 +9,6 @@ import java.util.Calendar;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.TimeZone;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -48,7 +47,7 @@ public class NewsServlet extends AnyServlet {
       HttpServletResponse response) throws IOException, ServletException {
     /* Create categories based on current system time. */
     Map<String, String[]> cutOffDates = new LinkedHashMap<>();
-    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+    Calendar cal = Calendar.getInstance();
     cal.set(Calendar.DAY_OF_WEEK, 1);
     cutOffDates.put(String.format("%tF", cal),
         new String[] { "This week", "week" });
diff --git a/src/main/java/org/torproject/metrics/web/ServerMain.java b/src/main/java/org/torproject/metrics/web/ServerMain.java
index 21f8529..263c687 100644
--- a/src/main/java/org/torproject/metrics/web/ServerMain.java
+++ b/src/main/java/org/torproject/metrics/web/ServerMain.java
@@ -10,6 +10,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.Locale;
+import java.util.TimeZone;
 
 public class ServerMain {
 
@@ -19,6 +20,7 @@ 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 jettyXml = Resource.newSystemResource("jetty.xml");
       logger.info("Reading configuration from '{}'.", jettyXml);
diff --git a/src/main/java/org/torproject/metrics/web/TableParameterChecker.java b/src/main/java/org/torproject/metrics/web/TableParameterChecker.java
index 8c3b4fa..4143a2a 100644
--- a/src/main/java/org/torproject/metrics/web/TableParameterChecker.java
+++ b/src/main/java/org/torproject/metrics/web/TableParameterChecker.java
@@ -10,7 +10,6 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.TimeZone;
 
 /**
  * Checks request parameters passed to generate tables.
@@ -41,7 +40,6 @@ public class TableParameterChecker {
    */
   public TableParameterChecker() {
     this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-    this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
 
     this.availableTables = new HashMap<>();
     for (Metric metric : ContentProvider.getInstance().getMetricsList()) {
diff --git a/src/main/java/org/torproject/metrics/web/TableServlet.java b/src/main/java/org/torproject/metrics/web/TableServlet.java
index c3d8d6e..891e803 100644
--- a/src/main/java/org/torproject/metrics/web/TableServlet.java
+++ b/src/main/java/org/torproject/metrics/web/TableServlet.java
@@ -11,7 +11,6 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
-import java.util.TimeZone;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -63,7 +62,6 @@ public class TableServlet extends MetricServlet {
     request.setAttribute("tableheader",
         this.tableHeaders.get(requestedId));
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
     Date defaultEndDate = new Date();
     Date defaultStartDate = new Date(defaultEndDate.getTime()
         - 90L * 24L * 60L * 60L * 1000L);
diff --git a/src/main/java/org/torproject/metrics/web/UpdateNews.java b/src/main/java/org/torproject/metrics/web/UpdateNews.java
index 07b1d75..bddb32d 100644
--- a/src/main/java/org/torproject/metrics/web/UpdateNews.java
+++ b/src/main/java/org/torproject/metrics/web/UpdateNews.java
@@ -15,6 +15,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
+import java.util.TimeZone;
 
 public class UpdateNews {
 
@@ -24,6 +25,7 @@ public class UpdateNews {
   /** Update news. */
   public static void main(String[] args) throws Exception {
     Locale.setDefault(Locale.US);
+    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
     URL textFile = new URL(
         "https://trac.torproject.org/projects/tor/wiki/doc/";
         + "MetricsTimeline?format=txt");

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits