package seedu.task.model.util;

import java.util.Calendar;

import seedu.task.commons.exceptions.IllegalValueException;

public class DateParser {
    public static final String DATE_STRING_ILLEGAL_FORMAT =
            "String given to the DateParser must be of the form YYYY/MM/DD HHMM";

    private static final int DEFAULT_SECONDS = 0;
    private static final String DATE_STRING_VALIDATION_REGEX = "[0-9]{4}/[0-1][0-9]/[0-3][0-9] [0-2][0-9][0-5][0-9]";

    public static Calendar parse(String date) throws IllegalValueException {
        if (!isValidDateString(date)) {
            throw new IllegalValueException(DATE_STRING_ILLEGAL_FORMAT);
        }
        Calendar cal = Calendar.getInstance();
        int year = getYear(date);
        int month = getMonth(date);
        int day = getDay(date);
        int hour = getHour(date);
        int minute = getMinute(date);
        cal.set(year, month, day, hour, minute, DEFAULT_SECONDS);
        return cal;
    }

    public static boolean isValidDateString(String test) {
        return test.matches(DATE_STRING_VALIDATION_REGEX);
    }

    private static int getYear(String date) {
        return Integer.parseInt(date.substring(0,  4));
    }

    private static int getMonth(String date) {
        return Integer.parseInt(date.substring(5,  7)) - 1;
    }

    private static int getDay(String date) {
        return Integer.parseInt(date.substring(8, 10));
    }

    private static int getHour(String date) {
        return Integer.parseInt(date.substring(11, 13));
    }

    private static int getMinute(String date) {
        return Integer.parseInt(date.substring(13));
    }
}

@@ -962,24 +962,467 @@
 cal;%0A    %7D%0A%0A
+    public static String toString(Calendar date) %7B%0A        String dateString;%0A        int year = date.get(Calendar.YEAR);%0A        int month = date.get(Calendar.MONTH);%0A        int day = date.get(Calendar.DATE);%0A        int hour = date.get(Calendar.HOUR_OF_DAY);%0A        int minute = date.get(Calendar.MINUTE);%0A%0A        dateString = String.format(%22%254d/%2502d/%2502d %2502d:%2502d%22, year, month+1, day, hour, minute);%0A%0A        return dateString;%0A    %7D%0A%0A
     public s

Add toString method to DateParser