SmartTimeFormat extends TimeFormat { public static int[] parseToHourAndMinutes(final String timeString) throws ParseException { String time = timeString; time = Strings.nullToEmpty(time).trim(); if (time.length() == 0) { throw new ParseException("String is empty", 1); } time = normalize(time); String[] splitted = time.split(":"); if (splitted.length != 2) { throw new ParseException("String '" + timeString + "' has an unsupported format", 1); } else { int[] result = new int[2]; for (int i = 0; i < 2; i++) { result[i] = Integer.parseInt(splitted[i]); } return result; } }  final Date parse(final String source, final ParsePosition pos); static int[] parseToHourAndMinutes(final String timeString);  }
@Test void parseToHourAndMinutesNormal() throws ParseException { int[] hoursAndMinutes = SmartTimeFormat.parseToHourAndMinutes("09:10"); assertEquals(hoursAndMinutes[0], 9); assertEquals(hoursAndMinutes[1], 10); }
@Test void parseToHourAndMinutesWithHoursOnly() throws ParseException { int[] hoursAndMinutes = SmartTimeFormat.parseToHourAndMinutes("9"); assertEquals(hoursAndMinutes[0], 9); assertEquals(hoursAndMinutes[1], 0); }
@Test void parseToHourAndMinutesWithDecimalMinutes() throws ParseException { int[] hoursAndMinutes = SmartTimeFormat.parseToHourAndMinutes("9,75"); assertEquals(hoursAndMinutes[0], 9); assertEquals(hoursAndMinutes[1], 45); }
@Test void parseToHourAndMinutesWithDecimalMinutesShort() throws ParseException { int[] hoursAndMinutes = SmartTimeFormat.parseToHourAndMinutes(",5"); assertEquals(hoursAndMinutes[0], 0); assertEquals(hoursAndMinutes[1], 30); }