mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 04:42:06 +01:00
Introduce and use DateUtil.toSecondsPrecision
This commit is contained in:
parent
2f44621657
commit
f3b7286eaf
3 changed files with 12 additions and 2 deletions
|
@ -45,6 +45,16 @@ public final class DateUtil {
|
||||||
return getParser().format(date);
|
return getParser().format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Round" a date down to seconds precision.
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Date toSecondsPrecision(Date date) {
|
||||||
|
long seconds = date.getTime() / 1000;
|
||||||
|
return new Date(seconds * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current date "rounded" to UTC precision.
|
* Return the current date "rounded" to UTC precision.
|
||||||
*
|
*
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest {
|
||||||
throws PGPException {
|
throws PGPException {
|
||||||
Date expirationDate = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 14);
|
Date expirationDate = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 14);
|
||||||
// round date for test stability
|
// round date for test stability
|
||||||
expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(expirationDate));
|
expirationDate = DateUtil.toSecondsPrecision(expirationDate);
|
||||||
|
|
||||||
PGPSecretKeyRing modded = PGPainless.modifyKeyRing(keys)
|
PGPSecretKeyRing modded = PGPainless.modifyKeyRing(keys)
|
||||||
.setExpirationDate(expirationDate, protector)
|
.setExpirationDate(expirationDate, protector)
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
|
||||||
@ExtendWith(TestAllImplementations.class)
|
@ExtendWith(TestAllImplementations.class)
|
||||||
public void testChangingExpirationTimeWithKeyWithoutPrefAlgos()
|
public void testChangingExpirationTimeWithKeyWithoutPrefAlgos()
|
||||||
throws IOException, PGPException {
|
throws IOException, PGPException {
|
||||||
Date expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(new Date()));
|
Date expirationDate = DateUtil.toSecondsPrecision(new Date());
|
||||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||||
|
|
||||||
SecretKeyRingProtector protector = new UnprotectedKeysProtector();
|
SecretKeyRingProtector protector = new UnprotectedKeysProtector();
|
||||||
|
|
Loading…
Reference in a new issue