fix #45 add DATE12

This commit is contained in:
Enrique Zamudio
2016-01-06 11:05:44 -06:00
parent a0c8413171
commit ab1d882476
9 changed files with 142 additions and 10 deletions
@@ -215,7 +215,7 @@ public class TestConfigParser {
Assert.assertEquals(IsoType.AMOUNT.getLength(), field4.getLength());
// check nested field num 4 from composite field 62
CompositeField compositeField62 = (CompositeField) isoMessage.<Object>getField(62).getValue();
CompositeField compositeField62 = isoMessage.<CompositeField>getField(62).getValue();
IsoValue<Object> nestedField4 = compositeField62.getField(0); // first in list
Assert.assertEquals(IsoType.ALPHA, nestedField4.getType());
Assert.assertEquals(13, nestedField4.getLength());
@@ -17,22 +17,25 @@ public class TestFormats {
@Test
public void testDateFormats() {
assert IsoType.DATE10.format(date, null).equals("0125213456");
assert IsoType.DATE4.format(date, null).equals("0125");
assert IsoType.DATE_EXP.format(date, null).equals("7301");
assert IsoType.TIME.format(date, null).equals("213456");
Assert.assertEquals("0125213456", IsoType.DATE10.format(date, null));
Assert.assertEquals("0125", IsoType.DATE4.format(date, null));
Assert.assertEquals("7301", IsoType.DATE_EXP.format(date, null));
Assert.assertEquals("213456", IsoType.TIME.format(date, null));
Assert.assertEquals("730125213456", IsoType.DATE12.format(date, null));
//Now with GMT
TimeZone gmt = TimeZone.getTimeZone("GMT");
Assert.assertEquals("0126033456", IsoType.DATE10.format(date, gmt));
Assert.assertEquals("0126", IsoType.DATE4.format(date, gmt));
Assert.assertEquals("7301", IsoType.DATE_EXP.format(date, gmt));
Assert.assertEquals("033456", IsoType.TIME.format(date, gmt));
Assert.assertEquals("730126033456", IsoType.DATE12.format(date, gmt));
//And now with GMT+1
gmt = TimeZone.getTimeZone("GMT+0100");
Assert.assertEquals("0126043456", IsoType.DATE10.format(date, gmt));
Assert.assertEquals("0126", IsoType.DATE4.format(date, gmt));
Assert.assertEquals("7301", IsoType.DATE_EXP.format(date, gmt));
Assert.assertEquals("043456", IsoType.TIME.format(date, gmt));
Assert.assertEquals("730126043456", IsoType.DATE12.format(date, gmt));
}
@Test
@@ -48,4 +48,17 @@ public class TestDates {
Assert.assertEquals(comp.getValue().getTime(), bin.getValue().getTime());
}
@Test
public void testDate12FutureTolerance() throws ParseException, IOException {
Date soon = new Date(System.currentTimeMillis() + 50000);
byte[] buf = IsoType.DATE12.format(soon, null).getBytes();
IsoValue<Date> comp = new Date12ParseInfo().parse(0, buf, 0, null);
assert comp.getValue().after(new Date());
//Now with the binary
ByteArrayOutputStream bout = new ByteArrayOutputStream();
comp.write(bout, true, false);
IsoValue<Date> bin = new Date12ParseInfo().parseBinary(0, bout.toByteArray(), 0, null);
Assert.assertEquals(comp.getValue().getTime(), bin.getValue().getTime());
}
}