private static final Pattern TIME_PATTERN = Pattern.compile("^\\d{1,2}(:?\\d{2})?([\\.:]?\\d{2})?$");
public RepeaterTime(String time) {
super(null);
String t = time.replaceAll(":", "");
Tick type;
int length = t.length();
if (length <= 2) {
int hours = Integer.parseInt(t);
int hoursInSeconds = hours * 60 * 60;
if (hours == 12) {
type = new Tick(0 * 60 * 60, true);
}
else {
type = new Tick(hoursInSeconds, true);
}
}
else if (length == 3) {
int hoursInSeconds = Integer.parseInt(t.substring(0, 1)) * 60 * 60;
int minutesInSeconds = Integer.parseInt(t.substring(1)) * 60;
type = new Tick(hoursInSeconds + minutesInSeconds, true);
}
else if (length == 4) {
boolean ambiguous = (time.contains(":") && Integer.parseInt(t.substring(0, 1)) != 0 && Integer.parseInt(t.substring(0, 2)) <= 12);
int hours = Integer.parseInt(t.substring(0, 2));
int hoursInSeconds = hours * 60 * 60;
int minutesInSeconds = Integer.parseInt(t.substring(2)) * 60;
if (hours == 12) {
type = new Tick(0 * 60 * 60 + minutesInSeconds, ambiguous);
}
else {
type = new Tick(hoursInSeconds + minutesInSeconds, ambiguous);
}
}
else if (length == 5) {
int hoursInSeconds = Integer.parseInt(t.substring(0, 1)) * 60 * 60;
int minutesInSeconds = Integer.parseInt(t.substring(1, 3)) * 60;
int seconds = Integer.parseInt(t.substring(3));
type = new Tick(hoursInSeconds + minutesInSeconds + seconds, true);
}
else if (length == 6) {
boolean ambiguous = (time.contains(":") && Integer.parseInt(t.substring(0, 1)) != 0 && Integer.parseInt(t.substring(0, 2)) <= 12);
int hours = Integer.parseInt(t.substring(0, 2));
int hoursInSeconds = hours * 60 * 60;
int minutesInSeconds = Integer.parseInt(t.substring(2, 4)) * 60;
int seconds = Integer.parseInt(t.substring(4, 6));
//type = new Tick(hoursInSeconds + minutesInSeconds + seconds, ambiguous);
if (hours == 12) {
type = new Tick(0 * 60 * 60 + minutesInSeconds + seconds, ambiguous);
}
else {
type = new Tick(hoursInSeconds + minutesInSeconds + seconds, ambiguous);
}
}
else {
throw new IllegalArgumentException("Time cannot exceed six digits");
}