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.
This commit is contained in:
Karsten Loesing 2020-04-01 12:45:37 +02:00
parent 334550d6d5
commit 9844bc523c
11 changed files with 6 additions and 19 deletions

@ -1 +1 @@
Subproject commit fd856466bcb260f53ef69a24c102d0e49d171cc3 Subproject commit b5e1a2d7b29e58cc0645f068a1ebf4377bf9d8b8

View File

@ -27,7 +27,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TimeZone;
import java.util.TreeMap; import java.util.TreeMap;
public class Main { public class Main {
@ -72,7 +71,6 @@ public class Main {
} }
SimpleDateFormat dateTimeFormat = new SimpleDateFormat( SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"); "yyyy-MM-dd HH:mm:ss");
dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
for (Descriptor descriptor : descriptorReader.readDescriptors(new File( for (Descriptor descriptor : descriptorReader.readDescriptors(new File(
org.torproject.metrics.stats.main.Main.descriptorsDir, org.torproject.metrics.stats.main.Main.descriptorsDir,
"recent/relay-descriptors/consensuses"))) { "recent/relay-descriptors/consensuses"))) {
@ -150,7 +148,6 @@ public class Main {
/* Aggregate statistics. */ /* Aggregate statistics. */
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String today = dateFormat.format(new Date()); String today = dateFormat.format(new Date());
SortedMap<String, List<Long>> preAggregatedValues = new TreeMap<>(); SortedMap<String, List<Long>> preAggregatedValues = new TreeMap<>();
try (BufferedReader br = new BufferedReader(new FileReader(resultsFile))) { try (BufferedReader br = new BufferedReader(new FileReader(resultsFile))) {

View File

@ -28,7 +28,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TimeZone;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
@ -184,7 +183,6 @@ public class Main {
+ "proceeding. To fix this, you'll have to re-import " + "proceeding. To fix this, you'll have to re-import "
+ "statistics for the following dates:"); + "statistics for the following dates:");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
for (long conflictingDate : conflictingDates) { for (long conflictingDate : conflictingDates) {
sb.append("\n ") sb.append("\n ")
.append(dateFormat.format(conflictingDate * ONE_DAY_IN_MILLIS)); .append(dateFormat.format(conflictingDate * ONE_DAY_IN_MILLIS));
@ -436,7 +434,6 @@ public class Main {
SortedMap<String, Short> aggregateStats, SortedMap<String, Short> aggregateStats,
SortedSet<RawStat> rawStats) { SortedSet<RawStat> rawStats) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String yesterday = dateFormat.format(System.currentTimeMillis() String yesterday = dateFormat.format(System.currentTimeMillis()
- ONE_DAY_IN_MILLIS); - ONE_DAY_IN_MILLIS);
SortedMap<String, List<Short>> fractionsByDateAndDirection SortedMap<String, List<Short>> fractionsByDateAndDirection

View File

@ -8,7 +8,6 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.TimeZone;
/** Utility class to format and parse dates and timestamps. */ /** Utility class to format and parse dates and timestamps. */
public class DateTimeHelper { public class DateTimeHelper {
@ -49,7 +48,6 @@ public class DateTimeHelper {
if (!threadDateFormats.containsKey(format)) { if (!threadDateFormats.containsKey(format)) {
DateFormat dateFormat = new SimpleDateFormat(format); DateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.setLenient(false); dateFormat.setLenient(false);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
threadDateFormats.put(format, dateFormat); threadDateFormats.put(format, dateFormat);
} }
return threadDateFormats.get(format); return threadDateFormats.get(format);

View File

@ -11,7 +11,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TimeZone;
/** /**
* Checks request parameters passed to graph-generating servlets. * Checks request parameters passed to graph-generating servlets.
@ -45,7 +44,6 @@ public class GraphParameterChecker {
*/ */
public GraphParameterChecker() { public GraphParameterChecker() {
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd"); this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
this.availableGraphs = new HashMap<>(); this.availableGraphs = new HashMap<>();
for (Metric metric : ContentProvider.getInstance().getMetricsList()) { for (Metric metric : ContentProvider.getInstance().getMetricsList()) {
if ("Graph".equals(metric.getType())) { if ("Graph".equals(metric.getType())) {

View File

@ -13,7 +13,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TimeZone;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -145,7 +144,6 @@ public class GraphServlet extends MetricServlet {
request.setAttribute("description", request.setAttribute("description",
this.descriptions.get(requestedId)); this.descriptions.get(requestedId));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date defaultEndDate = new Date(); Date defaultEndDate = new Date();
Date defaultStartDate = new Date(defaultEndDate.getTime() Date defaultStartDate = new Date(defaultEndDate.getTime()
- 90L * 24L * 60L * 60L * 1000L); - 90L * 24L * 60L * 60L * 1000L);

View File

@ -9,7 +9,6 @@ import java.util.Calendar;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -48,7 +47,7 @@ public class NewsServlet extends AnyServlet {
HttpServletResponse response) throws IOException, ServletException { HttpServletResponse response) throws IOException, ServletException {
/* Create categories based on current system time. */ /* Create categories based on current system time. */
Map<String, String[]> cutOffDates = new LinkedHashMap<>(); Map<String, String[]> cutOffDates = new LinkedHashMap<>();
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK, 1); cal.set(Calendar.DAY_OF_WEEK, 1);
cutOffDates.put(String.format("%tF", cal), cutOffDates.put(String.format("%tF", cal),
new String[] { "This week", "week" }); new String[] { "This week", "week" });

View File

@ -10,6 +10,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone;
public class ServerMain { public class ServerMain {
@ -19,6 +20,7 @@ public class ServerMain {
/** Starts the web server listening for incoming client connections. */ /** Starts the web server listening for incoming client connections. */
public static void main(String[] args) { public static void main(String[] args) {
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
try { try {
Resource jettyXml = Resource.newSystemResource("jetty.xml"); Resource jettyXml = Resource.newSystemResource("jetty.xml");
logger.info("Reading configuration from '{}'.", jettyXml); logger.info("Reading configuration from '{}'.", jettyXml);

View File

@ -10,7 +10,6 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TimeZone;
/** /**
* Checks request parameters passed to generate tables. * Checks request parameters passed to generate tables.
@ -41,7 +40,6 @@ public class TableParameterChecker {
*/ */
public TableParameterChecker() { public TableParameterChecker() {
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd"); this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
this.availableTables = new HashMap<>(); this.availableTables = new HashMap<>();
for (Metric metric : ContentProvider.getInstance().getMetricsList()) { for (Metric metric : ContentProvider.getInstance().getMetricsList()) {

View File

@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -63,7 +62,6 @@ public class TableServlet extends MetricServlet {
request.setAttribute("tableheader", request.setAttribute("tableheader",
this.tableHeaders.get(requestedId)); this.tableHeaders.get(requestedId));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date defaultEndDate = new Date(); Date defaultEndDate = new Date();
Date defaultStartDate = new Date(defaultEndDate.getTime() Date defaultStartDate = new Date(defaultEndDate.getTime()
- 90L * 24L * 60L * 60L * 1000L); - 90L * 24L * 60L * 60L * 1000L);

View File

@ -15,6 +15,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone;
public class UpdateNews { public class UpdateNews {
@ -24,6 +25,7 @@ public class UpdateNews {
/** Update news. */ /** Update news. */
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
URL textFile = new URL( URL textFile = new URL(
"https://trac.torproject.org/projects/tor/wiki/doc/" "https://trac.torproject.org/projects/tor/wiki/doc/"
+ "MetricsTimeline?format=txt"); + "MetricsTimeline?format=txt");