package seedu.tasklist.logic.parser;

import java.util.Date;
import java.util.List;

import org.ocpsoft.prettytime.nlp.PrettyTimeParser;

import seedu.tasklist.commons.exceptions.IllegalValueException;

//@@author A0143355J
public class DateParser {

    public static final String NO_DATES_MESSAGE = "No dates were detected, please enter a valid date after /d.";
    public static final String EXCESS_DATES = "Please enter only one date for Deadlines and two dates for Events.";

    /**
     * Uses PrettyTime NLP library to parse the dates into a list of Date objects
     */
    public static List<Date> parse (String date) throws IllegalValueException {
        List<Date> dates = new PrettyTimeParser().parse(date);
        if (dates.isEmpty()) {
            throw new IllegalValueException(NO_DATES_MESSAGE);
        }
        if (dates.size() > 2) {
            throw new IllegalValueException(EXCESS_DATES);
        }
        return dates;
    }
}

@@ -76,16 +76,80 @@
 il.List;
+%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0Aimport
@@ -538,16 +538,121 @@
 nts.%22;%0A%0A
+    private static Pattern ddmmRegex = Pattern.compile(%22%5C%5Cb(0?%5B12%5D%5B0-9%5D%7C3%5B01%5D)%5B/-%5D(0?%5B1-9%5D%7C1%5B012%5D)%5C%5Cb%22);%0A
     /**%0A
@@ -877,21 +877,39 @@
 ).parse(
+changeDateFormat(
 date)
+)
 ;%0A      
@@ -1099,32 +1099,32 @@
 TES);%0A        %7D%0A
-
         return d
@@ -1134,11 +1134,686 @@
 s;%0A    %7D
+%0A%0A    /**%0A     * PrettyTime parser reads dates in MMDD format%0A     * Changes date to that format to be read by PrettyTimeParser%0A     * @param date is the String for date captured by the parser%0A     * @return returns the string with DDMM swapped to be MMDD%0A     */%0A    private static String changeDateFormat(String date) %7B%0A        Matcher ddmm = ddmmRegex.matcher(date);%0A        while (ddmm.find()) %7B%0A            String dateFound = ddmm.group();%0A            String day = ddmm.group(1);%0A            String month = ddmm.group(2);%0A            String changedDate = month + %22/%22 + day;%0A            date = date.replaceAll(dateFound, changedDate);%0A        %7D%0A        return date;%0A    %7D
 %0A%7D%0A

change date regex to flip ddmm to mmdd