throws IOException, ParseException {
// full fractional seconds
Date myDate = new Date(1101980374187L);
byte[] encoded =
new DerOutputStream(gTime, myDate).encoded;
DerInputStream dis = useInputStream
? new DerInputStream(new ByteArrayInputStream(encoded))
: new DerInputStream(encoded);
assertEquals("full", myDate, gTime.decode(dis));
// 2 digit fractional seconds (last 0 must be trimmed out)
myDate = new Date(1101980374180L);
encoded =
new DerOutputStream(gTime, myDate).encoded;
dis = useInputStream
? new DerInputStream(new ByteArrayInputStream(encoded))
: new DerInputStream(encoded);
assertEquals("2 fraction", myDate, gTime.decode(dis));
// 1 digit fractional seconds (last 2 0s must be trimmed out)
myDate = new Date(1101980374100L);
encoded =
new DerOutputStream(gTime, myDate).encoded;
dis = useInputStream
? new DerInputStream(new ByteArrayInputStream(encoded))
: new DerInputStream(encoded);
assertEquals("1 fraction", myDate, gTime.decode(dis));
// no fractional seconds (last 3 0s and "." must be trimmed out)
myDate = new Date(1101980374000L);
encoded =
new DerOutputStream(gTime, myDate).encoded;
dis = useInputStream
? new DerInputStream(new ByteArrayInputStream(encoded))
: new DerInputStream(encoded);
assertEquals("no fraction", myDate, gTime.decode(dis));
// midnight
myDate = new SimpleDateFormat("MM.dd.yyyy HH:mm").
parse("06.06.2004 00:00");
encoded =
new DerOutputStream(gTime, myDate).encoded;
dis = useInputStream
? new DerInputStream(new ByteArrayInputStream(encoded))
: new DerInputStream(encoded);
assertEquals("midnight", myDate, gTime.decode(dis));
// date 100 ms
myDate = new Date(100L);
encoded =
new DerOutputStream(gTime, myDate).encoded;
dis = useInputStream
? new DerInputStream(new ByteArrayInputStream(encoded))
: new DerInputStream(encoded);
assertEquals("100ms", myDate, gTime.decode(dis));
}