/** Parses HH:MM:SS into array containing H,M,S elements */ public static int[] parseTimeOfDay(byte[] buffer) { int[] result = new int[3]; result[0] = NumbersParser.parsePositiveInt(buffer, 0, 2); result[1] = NumbersParser.parsePositiveInt(buffer, 3, 2); result[2] = NumbersParser.parsePositiveInt(buffer, 6, 2); if (result[0] >= 24 || result[1] >= 60 || result[2] >= 60) throw new FixParserException("Invalid time of day"); return result; }
/** @return number of milliseconds since midnight */ public static int parseTimeOfDay(byte[] buffer, int valueOffset, int valueLength) { // HH:mm:ss.SSS // 012345678901 int hours = NumbersParser.parsePositiveInt(buffer, valueOffset + 0, 2); int minutes = NumbersParser.parsePositiveInt(buffer, valueOffset + 3, 2); int seconds = NumbersParser.parsePositiveInt(buffer, valueOffset + 6, 2); int millis = (valueLength > 8) ? NumbersParser.parsePositiveInt(buffer, valueOffset + 9, 3) : 0; if (hours >= 24 || minutes >= 60 || seconds >= 60) throw new FixParserException("Invalid time of day"); return hours * MILLIS_PER_HOUR + minutes * MILLIS_PER_MINUTE + seconds * 1000 + millis; }