Set millis to 0 when parsing DATE4 fields. Fix UT for date4 parsing

git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@88 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
chochos
2011-07-23 04:28:00 +00:00
parent da7e788614
commit a0c22719bd
2 changed files with 10 additions and 4 deletions
@@ -51,6 +51,7 @@ public class Date4ParseInfo extends FieldParseInfo {
//Set the month in the date
cal.set(Calendar.MONTH, ((buf[pos] - 48) * 10) + buf[pos + 1] - 49);
cal.set(Calendar.DATE, ((buf[pos + 2] - 48) * 10) + buf[pos + 3] - 48);
cal.set(Calendar.MILLISECOND,0);
Date10ParseInfo.adjustWithFutureTolerance(cal);
return new IsoValue<Date>(type, cal.getTime(), null);
}
@@ -69,6 +70,7 @@ public class Date4ParseInfo extends FieldParseInfo {
//Set the month in the date
cal.set(Calendar.MONTH, tens[0] - 1);
cal.set(Calendar.DATE, tens[1]);
cal.set(Calendar.MILLISECOND,0);
Date10ParseInfo.adjustWithFutureTolerance(cal);
return new IsoValue<Date>(type, cal.getTime(), null);
}
+8 -4
View File
@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.GregorianCalendar;
import org.junit.*;
@@ -31,12 +32,15 @@ public class TestDates {
@Test
public void testDate4FutureTolerance() throws ParseException, IOException {
long now = System.currentTimeMillis();
long today = now - (now % 86400000l);
Date soon = new Date(now + 50000);
GregorianCalendar today = new GregorianCalendar();
Date soon = new Date(today.getTime().getTime() + 50000);
today.set(GregorianCalendar.HOUR,0);
today.set(GregorianCalendar.MINUTE,0);
today.set(GregorianCalendar.SECOND,0);
today.set(GregorianCalendar.MILLISECOND,0);
byte[] buf = IsoType.DATE4.format(soon).getBytes();
IsoValue<Date> comp = new Date4ParseInfo().parse(buf, 0, null);
assert comp.getValue().after(new Date(today));
Assert.assertEquals(comp.getValue(), today.getTime());
//Now with the binary
ByteArrayOutputStream bout = new ByteArrayOutputStream();
comp.write(bout, true);