Default the time to minutes if all else fails.

This commit is contained in:
graywolf336 2013-12-24 18:06:38 -06:00
parent 7e75f297d5
commit c4b1eb6d1a

View File

@ -64,6 +64,13 @@ public class Util {
return wand;
}
/**
* Converts a string like '20minutes' into the appropriate amount of milliseconds.
*
* @param time The string to convert.
* @return The time in milliseconds that is converted.
* @throws Exception if there are no matches
*/
public static Long getTime(String time) throws Exception {
Long t = 10L;
Matcher match = DURATION_PATTERN.matcher(time);
@ -79,8 +86,14 @@ public class Util {
else if ("days".equals(units) || "day".equals(units) || "d".equals(units))
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.DAYS);
}else {
try {
Long l = Long.parseLong(time);
t = TimeUnit.MILLISECONDS.convert(l, TimeUnit.MINUTES);
}catch(NumberFormatException e) {
throw new Exception("Invalid format.");
}
}
return t;
}