package seedu.taskitty.commons.util;

import java.time.DateTimeException;
import java.time.LocalTime;

/**
 * Converts a String to Date and vice versa.
 */
public class TimeUtil {
    private static final int TIME_COMPONENT_HOUR = 0;
    private static final int TIME_COMPONENT_MINUTE = 1;
    
    /**
     * Returns a LocalDate object representing the date from the string
     * 
     * @param dateString cannot be null
     * @throws DateTimeException if Date is invalid
     */
    public static LocalTime parseTime(String dateString) throws DateTimeException {
        assert dateString != null;
        
        LocalTime localTime;
        
        //TODO make clean (same as DateUtil)
        if (StringUtil.isInteger(dateString)) {
            localTime = parseFormat2(dateString);
        } else {
            String[] dateSplitByColon = dateString.split(":");
            localTime = parseFormat1(dateSplitByColon);
        }
        
        return localTime;
    }
    
    //TODO how to make clean?
    private static LocalTime parseFormat1(String[] timeComponents) throws DateTimeException {
        int hour = Integer.parseInt(timeComponents[TIME_COMPONENT_HOUR]);
        int minute = Integer.parseInt(timeComponents[TIME_COMPONENT_MINUTE]);
        
        return LocalTime.of(hour, minute);
    }
    
    private static LocalTime parseFormat2(String dateString) throws DateTimeException {
        assert dateString.length() == 4; //is it necessary to defend here?
        
        int hour = Integer.parseInt(dateString.substring(0, 2));
        int minute = Integer.parseInt(dateString.substring(2));
        
        return LocalTime.of(hour, minute);
    }
}

@@ -48,53 +48,287 @@
 va.t
-ime.DateTimeException;%0Aimport java.time.Local
+ext.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.time.DateTimeException;%0Aimport java.time.LocalDate;%0Aimport java.time.LocalDateTime;%0Aimport java.time.LocalTime;%0Aimport java.util.Date;%0A%0Aimport seedu.taskitty.model.task.TaskDate;%0Aimport seedu.taskitty.model.task.Task
 Time
@@ -1909,10 +1909,204 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * creates a current Time object for comparison with current time.%0A     * @return%0A     */%0A    public static LocalDateTime createCurrentTime() %7B%0A%09%09return LocalDateTime.now();%0A%09%7D%0A
 %7D%0A

create currentTime method in TimeUtil to get current time for comparison