Util: Consolidate and standardize date/time formatting (ticket #2016)

This commit is contained in:
zzz
2019-08-30 18:38:12 +00:00
parent 96d8385f49
commit a6e3621c06
25 changed files with 101 additions and 159 deletions

View File

@ -67,7 +67,7 @@ public class DatabaseInfo {
public static final int NETSPEED_EDITION_REV1 = 32;
public static final int NETSPEED_EDITION_REV1_V6 = 33;
private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
private String info;

View File

@ -3,7 +3,6 @@ package net.i2p.router;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Queue;
@ -52,13 +51,9 @@ public class MessageHistory {
public final static String PROP_MESSAGE_HISTORY_FILENAME = "router.historyFilename";
public final static String DEFAULT_MESSAGE_HISTORY_FILENAME = "messageHistory.txt";
private final SimpleDateFormat _fmt;
public MessageHistory(RouterContext context) {
_context = context;
_log = context.logManager().getLog(getClass());
_fmt = new SimpleDateFormat("yy/MM/dd.HH:mm:ss.SSS");
_fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
_unwrittenEntries = new LinkedBlockingQueue<String>();
_reinitializeJob = new ReinitializeJob();
_writeJob = new WriteJob();
@ -601,9 +596,7 @@ public class MessageHistory {
}
private final String getTime(long when) {
synchronized (_fmt) {
return _fmt.format(new Date(when));
}
return DataHelper.formatTime(when);
}
/**

View File

@ -8,7 +8,6 @@ package net.i2p.router;
*
*/
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@ -417,18 +416,10 @@ public class OutNetMessage implements CDPQEntry {
else
buf.append(0);
buf.append("ms: \t").append(name);
buf.append('=').append(formatDate(when.longValue()));
buf.append('=').append(new Date(when.longValue()));
buf.append("]\n");
lastWhen = when.longValue();
}
}
}
private final static SimpleDateFormat _fmt = new SimpleDateFormat("HH:mm:ss.SSS");
private final static String formatDate(long when) {
Date d = new Date(when);
synchronized (_fmt) {
return _fmt.format(d);
}
}
}

View File

@ -1,5 +1,7 @@
package net.i2p.router.tunnel;
import java.util.Date;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
import net.i2p.data.SessionKey;
@ -188,7 +190,7 @@ public class HopConfig {
buf.append(DataHelper.fromLong(_sendTunnelId, 0, 4));
}
buf.append(" exp. ").append(TunnelCreatorConfig.format(_expiration));
buf.append(" exp. ").append(new Date(_expiration));
int messagesProcessed = getProcessedMessagesCount();
if (messagesProcessed > 0)
buf.append(" used ").append(messagesProcessed).append("KB");

View File

@ -1,9 +1,7 @@
package net.i2p.router.tunnel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import net.i2p.data.Base64;
@ -43,7 +41,6 @@ public abstract class TunnelCreatorConfig implements TunnelInfo {
private long _peakThroughputLastCoallesce = System.currentTimeMillis();
// Make configurable? - but can't easily get to pool options from here
private static final int MAX_CONSECUTIVE_TEST_FAILURES = 3;
private static final SimpleDateFormat _fmt = new SimpleDateFormat("HH:mm:ss", Locale.UK);
/**
* For exploratory only (null destination)
@ -269,7 +266,7 @@ public abstract class TunnelCreatorConfig implements TunnelInfo {
buf.append("-->");
}
buf.append(" exp. ").append(getExpirationString());
buf.append(" exp. ").append(new Date(_expiration));
if (_replyMessageId > 0)
buf.append(" replyMsgID ").append(_replyMessageId);
if (_messagesProcessed > 0)
@ -279,15 +276,4 @@ public abstract class TunnelCreatorConfig implements TunnelInfo {
buf.append(" with ").append(_failures).append(" failures");
return buf.toString();
}
private String getExpirationString() {
return format(_expiration);
}
static String format(long date) {
Date d = new Date(date);
synchronized (_fmt) {
return _fmt.format(d);
}
}
}