--- C:/workspace/delta-fh2/qf Mon Jun 25 17:47:27 2012 +++ C:/workspace/delta-fh2/patched_qf Mon Jun 25 17:44:54 2012 @@ -28,23 +28,23 @@ import quickfix.FieldConvertError; import quickfix.SystemTime; /** * Convert between a timestamp and a String. A timestamp includes both a date * and a time. */ public class UtcTimestampConverter extends AbstractDateTimeConverter { private static ThreadLocal utcTimestampConverter = new ThreadLocal(); private final DateFormat utcTimestampFormat = createDateFormat("yyyyMMdd-HH:mm:ss"); private final DateFormat utcTimestampFormatMillis = createDateFormat("yyyyMMdd-HH:mm:ss.SSS"); - private static HashMap dateCache = new HashMap(); + private static HashMap dateCache = new HashMap(); /** * Convert a timestamp (represented as a Date) to a String. * @param d the date to convert * @param includeMilliseconds controls whether milliseconds are included in the result * @return the formatted timestamp */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); } @@ -63,45 +63,45 @@ // the base calendar. // /** * Convert a timestamp string into a Date. * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static Date convert(String value) throws FieldConvertError { verifyFormat(value); - String dateString = value.substring(0, 8); - Calendar c = getCalendarForDay(value, dateString); long timeOffset = (parseLong(value.substring(9, 11)) * 3600000L) + (parseLong(value.substring(12, 14)) * 60000L) + (parseLong(value.substring(15, 17)) * 1000L); if (value.length() == 21) { timeOffset += parseLong(value.substring(18, 21)); } - return new Date(c.getTimeInMillis() + timeOffset); + return new Date(getMillisForDay(value) + timeOffset); } - private static Calendar getCalendarForDay(String value, String dateString) { - Calendar c = dateCache.get(dateString); - if (c == null) { - c = new GregorianCalendar(1970, 0, 1, 0, 0, 0); + private static Long getMillisForDay(String value) { + String dateString = value.substring(0, 8); + Long millis = dateCache.get(dateString); + if (millis == null) { + Calendar c = new GregorianCalendar(1970, 0, 1, 0, 0, 0); c.setTimeZone(SystemTime.UTC_TIMEZONE); int year = Integer.parseInt(value.substring(0, 4)); int month = Integer.parseInt(value.substring(4, 6)); int day = Integer.parseInt(value.substring(6, 8)); c.set(year, month - 1, day); - dateCache.put(dateString, c); + millis = c.getTimeInMillis(); + dateCache.put(dateString, c.getTimeInMillis()); } - return c; + return millis; } private static void verifyFormat(String value) throws FieldConvertError { String type = "timestamp"; if (value.length() != 17 && value.length() != 21) { throwFieldConvertError(value, type); } assertDigitSequence(value, 0, 8, type); assertSeparator(value, 8, '-', type); assertDigitSequence(value, 9, 11, type); assertSeparator(value, 11, ':', type);