public static int parseTime(String time) {
        
        if (isEmpty(time)) {
            return -1;
        }
        Matcher match = timePattern.matcher(time);
        if (!match.matches()) {
            return -1;
        }
        int hours = parseInt(match.group(1));
        int minutes = parseInt(match.group(3));
        String aOrP = match.group(5);
        if (!isEmpty(aOrP) && aOrP.equalsIgnoreCase("p")) {
            if (hours < 12) {
                hours += 12;
            }
        } else {
            if (hours == 12 && !isEmpty(aOrP) && aOrP.equalsIgnoreCase("a")) {
                hours = 0;
            }
        }
        minutes += hours*60;
        return minutes;
    }