new supertype for all date/time parsers #21

This commit is contained in:
Enrique Zamudio
2013-12-18 18:38:43 -06:00
parent 515a632251
commit 1d7eadf2c7
@@ -0,0 +1,43 @@
package com.solab.iso8583.parse;
import com.solab.iso8583.IsoType;
import java.util.Calendar;
import java.util.TimeZone;
/**
* Abstract class for date/time parsers.
*
* @author Enrique Zamudio
* Date: 18/12/13 18:21
*/
public abstract class DateTimeParseInfo extends FieldParseInfo {
protected static final long FUTURE_TOLERANCE;
protected TimeZone tz;
static {
FUTURE_TOLERANCE = Long.parseLong(System.getProperty("j8583.future.tolerance", "900000"));
}
protected DateTimeParseInfo(IsoType type, int length) {
super(type, length);
}
public void setTimeZone(TimeZone value) {
tz = value;
}
public TimeZone getTimeZone() {
return tz;
}
public static void adjustWithFutureTolerance(Calendar cal) {
//We need to handle a small tolerance into the future (a couple of minutes)
long now = System.currentTimeMillis();
long then = cal.getTimeInMillis();
if (then > now && then-now > FUTURE_TOLERANCE) {
cal.add(Calendar.YEAR, -1);
}
}
}