mirror of
https://github.com/corda/corda.git
synced 2025-01-19 11:16:54 +00:00
Test date parsing/formatting
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
4f8b3f8865
commit
db99aada94
25
test/Dates.java
Normal file
25
test/Dates.java
Normal file
@ -0,0 +1,25 @@
|
||||
import java.text.FieldPosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class Dates {
|
||||
private final static long EPOCH = 1234567890;
|
||||
private final static String TEXT = "2009-02-13T23:31:30";
|
||||
|
||||
private static void expect(boolean v) {
|
||||
if (! v) throw new RuntimeException();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
Date date = format.parse("1970-01-01T00:00:00");
|
||||
expect(0 == date.getTime());
|
||||
|
||||
date = new Date(EPOCH * 1000l);
|
||||
String actual = format.format(date, new StringBuffer(), new FieldPosition(0)).toString();
|
||||
expect(TEXT.equals(actual));
|
||||
|
||||
date = format.parse(TEXT);
|
||||
expect(EPOCH == date.getTime() / 1000l);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user