Centralize time zone code in DataHelper

NewsManager should be a ClientApp, not a RouterApp
This commit is contained in:
zzz
2015-11-16 20:04:15 +00:00
parent 38a1a96db2
commit 6fb0692d57
11 changed files with 33 additions and 44 deletions

View File

@ -37,6 +37,7 @@ import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.zip.Deflater;
@ -1924,4 +1925,20 @@ public class DataHelper {
}
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();
}
}

View File

@ -22,7 +22,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
@ -479,9 +478,7 @@ public class LogManager implements Flushable {
if (!format.equals(""))
fmt.applyPattern(format);
// 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");
if (systemTimeZone != null)
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
fmt.setTimeZone(DataHelper.getSystemTimeZone(_context));
_dateFormatPattern = format;
_dateFormat = fmt;
return true;