forked from I2P_Developers/i2p.i2p
Centralize time zone code in DataHelper
NewsManager should be a ClientApp, not a RouterApp
This commit is contained in:
@@ -18,7 +18,6 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
@@ -2801,9 +2800,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
}
|
}
|
||||||
long dat = meta.getCreationDate();
|
long dat = meta.getCreationDate();
|
||||||
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
String systemTimeZone = _context.getProperty("i2p.systemTimeZone");
|
fmt.setTimeZone(DataHelper.getSystemTimeZone(_context));
|
||||||
if (systemTimeZone != null)
|
|
||||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
if (dat > 0) {
|
if (dat > 0) {
|
||||||
String date = fmt.format(new Date(dat));
|
String date = fmt.format(new Date(dat));
|
||||||
buf.append("<tr><td>");
|
buf.append("<tr><td>");
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
@@ -57,9 +56,7 @@ class ConnThrottler {
|
|||||||
_log = log;
|
_log = log;
|
||||||
// for logging
|
// for logging
|
||||||
_fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
|
_fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
|
||||||
String systemTimeZone = I2PAppContext.getGlobalContext().getProperty("i2p.systemTimeZone");
|
_fmt.setTimeZone(DataHelper.getSystemTimeZone(I2PAppContext.getGlobalContext()));
|
||||||
if (systemTimeZone != null)
|
|
||||||
_fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
new Cleaner();
|
new Cleaner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.app.ClientApp;
|
||||||
import net.i2p.app.ClientAppManager;
|
import net.i2p.app.ClientAppManager;
|
||||||
import net.i2p.app.ClientAppState;
|
import net.i2p.app.ClientAppState;
|
||||||
import static net.i2p.app.ClientAppState.*;
|
import static net.i2p.app.ClientAppState.*;
|
||||||
import net.i2p.router.app.RouterApp;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.util.FileUtil;
|
import net.i2p.util.FileUtil;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.TranslateReader;
|
import net.i2p.util.TranslateReader;
|
||||||
@@ -30,7 +30,7 @@ import org.cybergarage.xml.Node;
|
|||||||
*
|
*
|
||||||
* @since 0.9.23
|
* @since 0.9.23
|
||||||
*/
|
*/
|
||||||
public class NewsManager implements RouterApp {
|
public class NewsManager implements ClientApp {
|
||||||
|
|
||||||
private final I2PAppContext _context;
|
private final I2PAppContext _context;
|
||||||
private final Log _log;
|
private final Log _log;
|
||||||
@@ -233,9 +233,7 @@ public class NewsManager implements RouterApp {
|
|||||||
// Doesn't work if the date has a : in it, but SHORT hopefully does not
|
// Doesn't work if the date has a : in it, but SHORT hopefully does not
|
||||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
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
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
String systemTimeZone = _context.getProperty("i2p.systemTimeZone");
|
fmt.setTimeZone(DataHelper.getSystemTimeZone(_context));
|
||||||
if (systemTimeZone != null)
|
|
||||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
try {
|
try {
|
||||||
Date date = fmt.parse(newsContent.substring(0, colon));
|
Date date = fmt.parse(newsContent.substring(0, colon));
|
||||||
entry.updated = date.getTime();
|
entry.updated = date.getTime();
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import net.i2p.app.ClientAppManager;
|
import net.i2p.app.ClientAppManager;
|
||||||
import net.i2p.crypto.SU3File;
|
import net.i2p.crypto.SU3File;
|
||||||
@@ -579,9 +578,7 @@ class NewsFetcher extends UpdateRunner {
|
|||||||
return;
|
return;
|
||||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
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
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
String systemTimeZone = _context.getProperty("i2p.systemTimeZone");
|
fmt.setTimeZone(DataHelper.getSystemTimeZone(_context));
|
||||||
if (systemTimeZone != null)
|
|
||||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
for (NewsEntry e : entries) {
|
for (NewsEntry e : entries) {
|
||||||
if (e.title == null || e.content == null)
|
if (e.title == null || e.content == null)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
@@ -189,9 +188,7 @@ public class EventLogHelper extends FormHandler {
|
|||||||
|
|
||||||
SimpleDateFormat fmt = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
|
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
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
String systemTimeZone = _context.getProperty("i2p.systemTimeZone");
|
fmt.setTimeZone(DataHelper.getSystemTimeZone(_context));
|
||||||
if (systemTimeZone != null)
|
|
||||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
|
|
||||||
List<Map.Entry<Long, String>> entries = new ArrayList<Map.Entry<Long, String>>(events.entrySet());
|
List<Map.Entry<Long, String>> entries = new ArrayList<Map.Entry<Long, String>>(events.entrySet());
|
||||||
Collections.reverse(entries);
|
Collections.reverse(entries);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.text.DateFormat;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.app.ClientAppManager;
|
import net.i2p.app.ClientAppManager;
|
||||||
@@ -56,9 +55,7 @@ public class NewsFeedHelper extends HelperBase {
|
|||||||
if (!entries.isEmpty()) {
|
if (!entries.isEmpty()) {
|
||||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
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
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
String systemTimeZone = ctx.getProperty("i2p.systemTimeZone");
|
fmt.setTimeZone(DataHelper.getSystemTimeZone(ctx));
|
||||||
if (systemTimeZone != null)
|
|
||||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (NewsEntry entry : entries) {
|
for (NewsEntry entry : entries) {
|
||||||
if (i++ < start)
|
if (i++ < start)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import net.i2p.app.ClientAppManager;
|
import net.i2p.app.ClientAppManager;
|
||||||
import net.i2p.crypto.SigType;
|
import net.i2p.crypto.SigType;
|
||||||
@@ -634,9 +633,7 @@ public class SummaryBarRenderer {
|
|||||||
buf.append("<ul>\n");
|
buf.append("<ul>\n");
|
||||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
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
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
String systemTimeZone = _context.getProperty("i2p.systemTimeZone");
|
fmt.setTimeZone(DataHelper.getSystemTimeZone(_context));
|
||||||
if (systemTimeZone != null)
|
|
||||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
final int max = 2;
|
final int max = 2;
|
||||||
for (NewsEntry entry : entries) {
|
for (NewsEntry entry : entries) {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package i2p.susi.dns;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.data.DataHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a date in local time zone
|
* Format a date in local time zone
|
||||||
@@ -17,9 +17,7 @@ public abstract class FormatDate
|
|||||||
static {
|
static {
|
||||||
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
||||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
String systemTimeZone = I2PAppContext.getGlobalContext().getProperty("i2p.systemTimeZone");
|
fmt.setTimeZone(DataHelper.getSystemTimeZone(I2PAppContext.getGlobalContext()));
|
||||||
if (systemTimeZone != null)
|
|
||||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
_dateFormat = fmt;
|
_dateFormat = fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -276,12 +276,9 @@ class Mail {
|
|||||||
DateFormat localDateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
DateFormat localDateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||||
DateFormat longLocalDateFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
DateFormat longLocalDateFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
||||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
String systemTimeZone = I2PAppContext.getGlobalContext().getProperty("i2p.systemTimeZone");
|
TimeZone tz = DataHelper.getSystemTimeZone(I2PAppContext.getGlobalContext());
|
||||||
if (systemTimeZone != null) {
|
localDateFormatter.setTimeZone(tz);
|
||||||
TimeZone tz = TimeZone.getTimeZone(systemTimeZone);
|
longLocalDateFormatter.setTimeZone(tz);
|
||||||
localDateFormatter.setTimeZone(tz);
|
|
||||||
longLocalDateFormatter.setTimeZone(tz);
|
|
||||||
}
|
|
||||||
DateFormat mailDateFormatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH );
|
DateFormat mailDateFormatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH );
|
||||||
|
|
||||||
error = "";
|
error = "";
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import java.util.Iterator;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
@@ -1924,4 +1925,20 @@ public class DataHelper {
|
|||||||
}
|
}
|
||||||
return p.split(s, limit);
|
return p.split(s, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The system's time zone, which is probably different from the
|
||||||
|
* JVM time zone, because Router changes the JVM default to GMT.
|
||||||
|
* It saves the old default in the context properties where we can get it.
|
||||||
|
* Use this to format a time in local time zone with DateFormat.setTimeZone().
|
||||||
|
*
|
||||||
|
* @return non-null
|
||||||
|
* @since 0.9.24
|
||||||
|
*/
|
||||||
|
public static TimeZone getSystemTimeZone(I2PAppContext ctx) {
|
||||||
|
String systemTimeZone = ctx.getProperty("i2p.systemTimeZone");
|
||||||
|
if (systemTimeZone != null)
|
||||||
|
return TimeZone.getTimeZone(systemTimeZone);
|
||||||
|
return TimeZone.getDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import java.util.Map;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@@ -479,9 +478,7 @@ public class LogManager implements Flushable {
|
|||||||
if (!format.equals(""))
|
if (!format.equals(""))
|
||||||
fmt.applyPattern(format);
|
fmt.applyPattern(format);
|
||||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
String systemTimeZone = _context.getProperty("i2p.systemTimeZone");
|
fmt.setTimeZone(DataHelper.getSystemTimeZone(_context));
|
||||||
if (systemTimeZone != null)
|
|
||||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
|
||||||
_dateFormatPattern = format;
|
_dateFormatPattern = format;
|
||||||
_dateFormat = fmt;
|
_dateFormat = fmt;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user