Introduce and use DateUtil.toSecondsPrecision

This commit is contained in:
Paul Schaub 2021-12-28 01:35:12 +01:00
parent 2f44621657
commit f3b7286eaf
3 changed files with 12 additions and 2 deletions

View File

@ -45,6 +45,16 @@ public final class DateUtil {
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.
*

View File

@ -157,7 +157,7 @@ public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest {
throws PGPException {
Date expirationDate = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 14);
// round date for test stability
expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(expirationDate));
expirationDate = DateUtil.toSecondsPrecision(expirationDate);
PGPSecretKeyRing modded = PGPainless.modifyKeyRing(keys)
.setExpirationDate(expirationDate, protector)

View File

@ -100,7 +100,7 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
@ExtendWith(TestAllImplementations.class)
public void testChangingExpirationTimeWithKeyWithoutPrefAlgos()
throws IOException, PGPException {
Date expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(new Date()));
Date expirationDate = DateUtil.toSecondsPrecision(new Date());
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
SecretKeyRingProtector protector = new UnprotectedKeysProtector();