Replace use of Utils.currentTimeMillis() with Utils.currentTimeSeconds() where appropriate.

This commit is contained in:
Jakob Janecek 2019-04-14 19:18:16 +02:00
parent 66289d6f39
commit a00f751a56
3 changed files with 10 additions and 6 deletions

View file

@ -427,12 +427,16 @@ public class Utils {
return mockTime != null ? mockTime : new Date();
}
// TODO: Replace usages of this where the result is / 1000 with currentTimeSeconds.
/** Returns the current time in milliseconds since the epoch, or a mocked out equivalent. */
/**
* Returns the current time in milliseconds since the epoch, or a mocked out equivalent.
*/
public static long currentTimeMillis() {
return mockTime != null ? mockTime.getTime() : System.currentTimeMillis();
}
/**
* Returns the current time in seconds since the epoch, or a mocked out equivalent.
*/
public static long currentTimeSeconds() {
return currentTimeMillis() / 1000;
}

View file

@ -990,7 +990,7 @@ public class Wallet extends BaseTaggableObject
* Same as {@link #addWatchedAddress(Address, long)} with the current time as the creation time.
*/
public boolean addWatchedAddress(final Address address) {
long now = Utils.currentTimeMillis() / 1000;
long now = Utils.currentTimeSeconds();
return addWatchedAddresses(Lists.newArrayList(address), now) == 1;
}

View file

@ -351,7 +351,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
wallet.addOrUpdateExtension(stateStorage);
Utils.setMockClock(); // Use mock clock
final long EXPIRE_TIME = Utils.currentTimeMillis()/1000 + 60*60*24;
final long EXPIRE_TIME = Utils.currentTimeSeconds() + 60*60*24;
serverState = makeServerState(mockBroadcaster, serverWallet, serverKey, EXPIRE_TIME);
assertEquals(getInitialServerState(), serverState.getState());
@ -702,7 +702,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE), wallet.getBalance());
Utils.setMockClock(); // Use mock clock
final long EXPIRE_TIME = Utils.currentTimeMillis()/1000 + 60*60*24;
final long EXPIRE_TIME = Utils.currentTimeSeconds() + 60*60*24;
serverState = makeServerState(mockBroadcaster, serverWallet, serverKey, EXPIRE_TIME);
assertEquals(getInitialServerState(), serverState.getState());
@ -815,7 +815,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, true));
Utils.setMockClock(); // Use mock clock
final long EXPIRE_TIME = Utils.currentTimeMillis()/1000 + 60*60*24;
final long EXPIRE_TIME = Utils.currentTimeSeconds() + 60*60*24;
serverState = makeServerState(mockBroadcaster, serverWallet, serverKey, EXPIRE_TIME);
assertEquals(getInitialServerState(), serverState.getState());