forked from I2P_Developers/i2p.i2p
Util: Consolidate and standardize date/time formatting (ticket #2016)
This commit is contained in:
@@ -248,17 +248,26 @@ public class NewsManager implements ClientApp {
|
||||
int colon = newsContent.indexOf(": ");
|
||||
if (colon > 0 && colon <= 10) {
|
||||
// Parse the format we wrote it out in, in NewsFetcher.outputOldNewsXML()
|
||||
// Doesn't work if the date has a : in it, but SHORT hopefully does not
|
||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
// Doesn't work if the date has a : in it, but SHORT and MEDIUM hopefully do not
|
||||
// Was originally SHORT, switched to MEDIUM in 0.9.43
|
||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
|
||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
try {
|
||||
Date date = fmt.parse(newsContent.substring(0, colon));
|
||||
entry.updated = date.getTime();
|
||||
newsContent = newsContent.substring(colon + 2);
|
||||
} catch (ParseException pe) {
|
||||
// can't find date, will be zero
|
||||
// try SHORT
|
||||
try {
|
||||
fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
Date date = fmt.parse(newsContent.substring(0, colon));
|
||||
entry.updated = date.getTime();
|
||||
} catch (ParseException pe2) {
|
||||
// can't find date, will be zero
|
||||
}
|
||||
}
|
||||
newsContent = newsContent.substring(colon + 2);
|
||||
}
|
||||
}
|
||||
int end = newsContent.indexOf("</h3>");
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -391,9 +390,7 @@ public class Analysis extends JobImpl implements RouterApp {
|
||||
if (threshold < MIN_BLOCK_POINTS)
|
||||
threshold = MIN_BLOCK_POINTS;
|
||||
} catch (NumberFormatException nfe) {}
|
||||
DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
|
||||
dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
String day = dfmt.format(now);
|
||||
String day = DataHelper.formatTime(now);
|
||||
for (Map.Entry<Hash, Points> e : points.entrySet()) {
|
||||
double p = e.getValue().getPoints();
|
||||
if (p >= threshold) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@@ -635,8 +634,6 @@ class NewsFetcher extends UpdateRunner {
|
||||
}
|
||||
Blocklist bl = _context.blocklist();
|
||||
Banlist ban = _context.banlist();
|
||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
String reason = "Blocklist feed " + new Date(ble.updated);
|
||||
int banned = 0;
|
||||
for (Iterator<String> iter = ble.entries.iterator(); iter.hasNext(); ) {
|
||||
@@ -764,16 +761,13 @@ class NewsFetcher extends UpdateRunner {
|
||||
out.write("-->\n");
|
||||
if (entries == null)
|
||||
return;
|
||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
for (NewsEntry e : entries) {
|
||||
if (e.title == null || e.content == null)
|
||||
continue;
|
||||
Date date = new Date(e.updated);
|
||||
out.write("<!-- Entry Date: " + date + " -->\n");
|
||||
out.write("<!-- Entry Date: " + e.updated + " -->\n");
|
||||
out.write("<h3>");
|
||||
out.write(fmt.format(date));
|
||||
// Warning - update NewsHandler.parseNews() if you change the format
|
||||
out.write(DataHelper.formatDate(e.updated));
|
||||
out.write(": ");
|
||||
out.write(e.title);
|
||||
out.write("</h3>\n");
|
||||
|
||||
@@ -65,7 +65,7 @@ public class NewsFeedHelper extends HelperBase {
|
||||
}
|
||||
}
|
||||
if (!entries.isEmpty()) {
|
||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
|
||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(ctx));
|
||||
int i = 0;
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.router.RouterContext;
|
||||
@@ -201,7 +199,7 @@ public class NewsHelper extends ContentHelper {
|
||||
|
||||
/**
|
||||
* Convert long date stamp to
|
||||
* '07-Jul 21:09 UTC' with month name in the system locale
|
||||
* date/time in the system locale, local time zone
|
||||
* @return null if ver = null
|
||||
* @since 0.9.4 moved from NewsFetcher
|
||||
*/
|
||||
@@ -209,7 +207,7 @@ public class NewsHelper extends ContentHelper {
|
||||
if (ver != null) {
|
||||
try {
|
||||
long modtime = Long.parseLong(ver);
|
||||
return (new SimpleDateFormat("dd-MMM HH:mm")).format(new Date(modtime)) + " UTC";
|
||||
return DataHelper.formatTime(modtime);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package net.i2p.router.web.helpers;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
@@ -289,7 +287,7 @@ public class ConfigClientsHelper extends HelperBase {
|
||||
ms = Long.parseLong(s);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
if (ms > 0) {
|
||||
String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(ms));
|
||||
String date = DataHelper.formatTime(ms);
|
||||
desc.append("<tr><td><b>")
|
||||
.append(_t("Date")).append("</b></td><td>").append(date);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,9 @@ package net.i2p.router.web.helpers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.Collator;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -187,17 +184,13 @@ public class EventLogHelper extends FormHandler {
|
||||
}
|
||||
buf.append("</th></tr>");
|
||||
|
||||
SimpleDateFormat fmt = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
|
||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
|
||||
List<Map.Entry<Long, String>> entries = new ArrayList<Map.Entry<Long, String>>(events.entrySet());
|
||||
Collections.reverse(entries);
|
||||
for (Map.Entry<Long, String> e : entries) {
|
||||
long time = e.getKey().longValue();
|
||||
String event = e.getValue();
|
||||
buf.append("<tr><td>");
|
||||
buf.append(fmt.format(new Date(time)));
|
||||
buf.append(DataHelper.formatTime(time));
|
||||
buf.append("</td><td>");
|
||||
if (isAll) {
|
||||
String[] s = DataHelper.split(event, " ", 2);
|
||||
|
||||
@@ -3,9 +3,7 @@ package net.i2p.router.web.helpers;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -972,9 +970,6 @@ class SummaryBarRenderer {
|
||||
entries = nmgr.getEntries();
|
||||
}
|
||||
if (!entries.isEmpty()) {
|
||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
int i = 0;
|
||||
// show a min of 1, max of 3, none older than 60 days over min
|
||||
// Except, if news fetching is disabled, min is 0 and oldest is 7 days.
|
||||
@@ -1003,9 +998,8 @@ class SummaryBarRenderer {
|
||||
.append(consoleNonce)
|
||||
.append("\"");
|
||||
if (entry.updated > 0) {
|
||||
Date date = new Date(entry.updated);
|
||||
buf.append(" title=\"")
|
||||
.append(_t("Published")).append(": ").append(fmt.format(date)).append("\"");
|
||||
.append(_t("Published")).append(": ").append(DataHelper.formatDate(entry.updated)).append("\"");
|
||||
}
|
||||
buf.append(">");
|
||||
buf.append(entry.title)
|
||||
|
||||
@@ -64,7 +64,6 @@ public class SybilRenderer {
|
||||
private final RouterContext _context;
|
||||
private final Log _log;
|
||||
private final DecimalFormat fmt = new DecimalFormat("#0.00");
|
||||
private final DateFormat dfmt;
|
||||
|
||||
private static final int PAIRMAX = Analysis.PAIRMAX;
|
||||
private static final int MAX = Analysis.MAX;
|
||||
@@ -76,8 +75,6 @@ public class SybilRenderer {
|
||||
public SybilRenderer(RouterContext ctx) {
|
||||
_context = ctx;
|
||||
_log = ctx.logManager().getLog(SybilRenderer.class);
|
||||
dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
|
||||
dfmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,13 +206,13 @@ public class SybilRenderer {
|
||||
points = ps.load(date);
|
||||
} catch (IOException ioe) {
|
||||
_log.error("loading stored analysis for date: " + date, ioe);
|
||||
out.write("<b>Failed to load analysis for " + dfmt.format(new Date(date)) + "</b>: " +
|
||||
out.write("<b>Failed to load analysis for " + DataHelper.formatTime(date) + "</b>: " +
|
||||
DataHelper.escapeHTML(ioe.toString()));
|
||||
return;
|
||||
}
|
||||
if (points.isEmpty()) {
|
||||
_log.error("empty stored analysis or bad file format for date: " + date);
|
||||
out.write("<b>Corrupt analysis file for " + dfmt.format(new Date(date)) + "</b>");
|
||||
out.write("<b>Corrupt analysis file for " + DataHelper.formatTime(date) + "</b>");
|
||||
} else {
|
||||
renderThreatsHTML(out, buf, date, points);
|
||||
}
|
||||
@@ -266,7 +263,7 @@ public class SybilRenderer {
|
||||
buf.append(" selected=\"selected\"");
|
||||
first = false;
|
||||
}
|
||||
buf.append('>').append(dfmt.format(new Date(date.longValue()))).append("</option>\n");
|
||||
buf.append('>').append(DataHelper.formatTime(date.longValue())).append("</option>\n");
|
||||
}
|
||||
buf.append("</select>\n" +
|
||||
"<input type=\"submit\" name=\"action\" class=\"go\" value=\"Review analysis\" />" +
|
||||
@@ -366,7 +363,7 @@ public class SybilRenderer {
|
||||
buf.append("<div id=\"sybils_summary\">\n" +
|
||||
"<b>Average closest floodfill distance:</b> ").append(fmt.format(avgMinDist)).append("<br>\n" +
|
||||
"<b>Routing Data:</b> \"").append(DataHelper.getUTF8(_context.routerKeyGenerator().getModData()))
|
||||
.append("\" <b>Last Changed:</b> ").append(dfmt.format(new Date(_context.routerKeyGenerator().getLastChanged()))).append("<br>\n" +
|
||||
.append("\" <b>Last Changed:</b> ").append(DataHelper.formatTime(_context.routerKeyGenerator().getLastChanged())).append("<br>\n" +
|
||||
"<b>Next Routing Data:</b> \"").append(DataHelper.getUTF8(_context.routerKeyGenerator().getNextModData()))
|
||||
.append("\" <b>Rotates in:</b> ").append(DataHelper.formatDuration(_context.routerKeyGenerator().getTimeTillMidnight())).append("\n" +
|
||||
"</div>\n");
|
||||
@@ -509,7 +506,7 @@ public class SybilRenderer {
|
||||
List<Hash> warns = new ArrayList<Hash>(points.keySet());
|
||||
Collections.sort(warns, new PointsComparator(points));
|
||||
ReasonComparator rcomp = new ReasonComparator();
|
||||
buf.append("<h3 id=\"threats\" class=\"sybils\">Routers with Most Threat Points as of " + dfmt.format(new Date(date)) + "</h3>");
|
||||
buf.append("<h3 id=\"threats\" class=\"sybils\">Routers with Most Threat Points as of " + DataHelper.formatTime(date) + "</h3>");
|
||||
for (Hash h : warns) {
|
||||
Points pp = points.get(h);
|
||||
double p = pp.getPoints();
|
||||
|
||||
Reference in New Issue
Block a user