Skip to content

Commit c2af444

Browse files
committed
AbstractPgpKeyPairTest: Add parseUTCTimestamp() method
1 parent c7ece0f commit c2af444

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pg/src/test/java/org/bouncycastle/openpgp/test/AbstractPgpKeyPairTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,30 @@
1010
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
1111

1212
import java.security.KeyPair;
13+
import java.text.ParseException;
14+
import java.text.SimpleDateFormat;
1315
import java.util.Date;
16+
import java.util.TimeZone;
1417

1518
public abstract class AbstractPgpKeyPairTest
1619
extends AbstractPacketTest
1720
{
1821

22+
public static Date parseUTCTimestamp(String timestamp)
23+
{
24+
// Not thread safe, so we use a local variable
25+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
26+
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
27+
try
28+
{
29+
return dateFormat.parse(timestamp);
30+
}
31+
catch (ParseException e)
32+
{
33+
throw new RuntimeException(e);
34+
}
35+
}
36+
1937
public Date currentTimeRounded()
2038
{
2139
Date now = new Date();

0 commit comments

Comments
 (0)