public static TimeOfDayValue stringToTimeOfDay(String s)
throws InvalidQueryException {
String[] split = s.split(":");
if (split.length != 3) {
log.error(String.format(timeOfDayMessage, s));
throw new InvalidQueryException(String.format(timeOfDayMessage, s));
}
try {
int hour = Integer.parseInt(split[0]);
int minute = Integer.parseInt(split[1]);
int second;
if (split[2].contains(".")) {
String[] secondMilliSplit = split[2].split(".");
if (secondMilliSplit.length != 2) {
log.error(String.format(timeOfDayMessage, s));
throw new InvalidQueryException(String.format(timeOfDayMessage, s));
}
second = Integer.parseInt(secondMilliSplit[0]);
int milli = Integer.parseInt(secondMilliSplit[1]);
return new TimeOfDayValue(hour, minute, second, milli);
} else {
second = Integer.parseInt(split[2]);
return new TimeOfDayValue(hour, minute, second);
}
} catch (NumberFormatException e) {
log.error(String.format(timeOfDayMessage, s));
throw new InvalidQueryException(String.format(timeOfDayMessage, s));
} catch (IllegalArgumentException e) {
log.error(String.format(timeOfDayMessage, s));
throw new InvalidQueryException(String.format(timeOfDayMessage, s));
}
}