//@@author A0141094M

package seedu.typed.logic.parser;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import seedu.typed.commons.exceptions.IllegalValueException;
import seedu.typed.model.task.DateTime;

public class DateTimeParserTest {

    String invalidDate;
    String dateExactUSFormat;
    String dateShortUSFormat;
    String dateNaturalShort;
    String dateNaturalLong;
    String dateNaturalSentence;
    String dateTmrShort;
    String dateTmrLong;
    String invalidTime;
    String time24Format;
    String time12FormatLong;
    String time12FormatShort;
    String timeNatural;

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Before
    public void setUp() {
        invalidDate = "22 decem";
        dateExactUSFormat = "12/22/2017"; // the standard
        dateShortUSFormat = "12/22";
        dateNaturalShort = "22 dec";
        dateNaturalLong = "22 december 2017";
        dateNaturalSentence = "the 22nd of december";
        dateTmrShort = "tmr";
        dateTmrLong = "tomorrow";
        invalidTime = "20hr";
        time24Format = "2000"; // the standard
        time12FormatLong = "0800pm";
        time12FormatShort = "8pm";
        timeNatural = "night";
    }

    @After
    public void tearDown() {
        invalidDate = null;
        dateExactUSFormat = null;
        dateShortUSFormat = null;
        dateNaturalShort = null;
        dateNaturalLong = null;
        dateNaturalSentence = null;
        dateTmrShort = null;
        dateTmrLong = null;
        invalidTime = null;
        time24Format = null;
        time12FormatLong = null;
        time12FormatShort = null;
        timeNatural = null;
    }

    private void assertExceptionThrown() {
        thrown.expect(AssertionError.class);
    }

    private DateTime genStandardDate() throws IllegalValueException {
        return DateTimeParser.getDateTimeFromString(dateExactUSFormat);
    }

    private void isDateEqual(DateTime dt, DateTime dt2) {
        assertEquals(dt.getYear(), dt2.getYear());
        assertEquals(dt.getMonth(), dt2.getMonth());
        assertEquals(dt.getDay(), dt2.getDay());
    }

    @Test
    public void parsingNaturalDates_invalidDate_illegalValueExceptionThrown() throws IllegalValueException {
        assertExceptionThrown();
        isDateEqual(genStandardDate(), DateTimeParser.getDateTimeFromString(invalidDate));
    }

    @Test
    public void parsingNaturalDates_dateShortUSFormat_equals() throws IllegalValueException {
        DateTime dateTimeShortUSFormat = DateTimeParser.getDateTimeFromString(dateShortUSFormat);
        isDateEqual(genStandardDate(), dateTimeShortUSFormat);
    }

    @Test
    public void parsingNaturalDates_dateNaturalShort_equals() throws IllegalValueException {
        DateTime dateTimeNaturalShort = DateTimeParser.getDateTimeFromString(dateNaturalShort);
        isDateEqual(genStandardDate(), dateTimeNaturalShort);
    }

    @Test
    public void parsingNaturalDates_dateNaturalLong_equals() throws IllegalValueException {
        DateTime dateTimeNaturalLong = DateTimeParser.getDateTimeFromString(dateNaturalLong);
        isDateEqual(genStandardDate(), dateTimeNaturalLong);
    }

    @Test
    public void parsingNaturalDates_dateNaturalSentence_equals() throws IllegalValueException {
        DateTime dateTimeNaturalSentence = DateTimeParser.getDateTimeFromString(dateNaturalSentence);
        isDateEqual(genStandardDate(), dateTimeNaturalSentence);
    }

    @Test
    public void parsingNaturalDates_dateTomorrowShorthands_equals() throws IllegalValueException {
        DateTime dateTimeTmrShort = DateTimeParser.getDateTimeFromString(dateTmrShort);
        DateTime dateTimeTmrLong = DateTimeParser.getDateTimeFromString(dateTmrLong);
        isDateEqual(dateTimeTmrShort, dateTimeTmrLong);
    }

    // ----------------------------------------------------------------------------------------

    private DateTime genStandardTime() throws IllegalValueException {
        return DateTimeParser.getDateTimeFromString(time24Format);
    }

    /*
    private void isTimeEqual(DateTime dt, DateTime dt2) {
        assertEquals(dt, dt2);
    }

    @Test
    public void parsingNaturalDates_invalidTime_illegalValueExceptionThrown() throws IllegalValueException {
        assertExceptionThrown("");
        DateTimeParser.getDateTimeFromString(invalidTime);
    }

    @Test
    public void parsingNaturalTimes_time12FormatShort_equals() throws IllegalValueException {
        DateTime dateTime12FormatShort = DateTimeParser.getDateTimeFromString(time12FormatShort);
        assertEquals(genStandardTime(), dateTime12FormatShort);
    }

    @Test
    public void parsingNaturalTimes_time12FormatLong_equals() throws IllegalValueException {
        DateTime dateTime12FormatLong = DateTimeParser.getDateTimeFromString(time12FormatLong);
        assertEquals(genStandardTime(), dateTime12FormatLong);
    }

    @Test
    public void parsingNaturalTimes_timeNaturalTime_equals() throws IllegalValueException {
        DateTime dateTimeNatural = DateTimeParser.getDateTimeFromString(timeNatural);
        assertEquals(genStandardTime(), dateTimeNatural);
    }

    */

}
//@@author

@@ -563,118 +563,29 @@
 date
-TmrShort;%0A    String dateTmrLong;%0A    String invalidTime;%0A    String time24Format;%0A    String time12FormatLong
+NaturalSentenceFormal
 ;%0A  
@@ -593,28 +593,23 @@
  String 
-time12Format
+dateTmr
 Short;%0A 
@@ -618,27 +618,27 @@
  String 
-timeNatural
+dateTmrLong
 ;%0A%0A    @
@@ -1007,24 +1007,79 @@
  december%22;%0A
+        dateNaturalSentenceFormal = %2222nd day of dec%22;%0A
         date
@@ -1134,188 +1134,8 @@
 w%22;%0A
-        invalidTime = %2220hr%22;%0A        time24Format = %222000%22; // the standard%0A        time12FormatLong = %220800pm%22;%0A        time12FormatShort = %228pm%22;%0A        timeNatural = %22night%22;%0A
     
@@ -1366,32 +1366,74 @@
 entence = null;%0A
+        dateNaturalSentenceFormal = null;%0A
         dateTmrS
@@ -1477,160 +1477,8 @@
 ll;%0A
-        invalidTime = null;%0A        time24Format = null;%0A        time12FormatLong = null;%0A        time12FormatShort = null;%0A        timeNatural = null;%0A
     
@@ -3268,32 +3268,336 @@
 ntence);%0A    %7D%0A%0A
+    @Test%0A    public void parsingNaturalDates_dateNaturalSentenceFormal_equals() throws IllegalValueException %7B%0A        DateTime dateTimeNaturalSentenceFormal = DateTimeParser.getDateTimeFromString(dateNaturalSentenceFormal);%0A        isDateEqual(genStandardDate(), dateTimeNaturalSentenceFormal);%0A    %7D%0A%0A
     @Test%0A    pu
@@ -3930,1375 +3930,8 @@
  %7D%0A%0A
-    // ----------------------------------------------------------------------------------------%0A%0A    private DateTime genStandardTime() throws IllegalValueException %7B%0A        return DateTimeParser.getDateTimeFromString(time24Format);%0A    %7D%0A%0A    /*%0A    private void isTimeEqual(DateTime dt, DateTime dt2) %7B%0A        assertEquals(dt, dt2);%0A    %7D%0A%0A    @Test%0A    public void parsingNaturalDates_invalidTime_illegalValueExceptionThrown() throws IllegalValueException %7B%0A        assertExceptionThrown(%22%22);%0A        DateTimeParser.getDateTimeFromString(invalidTime);%0A    %7D%0A%0A    @Test%0A    public void parsingNaturalTimes_time12FormatShort_equals() throws IllegalValueException %7B%0A        DateTime dateTime12FormatShort = DateTimeParser.getDateTimeFromString(time12FormatShort);%0A        assertEquals(genStandardTime(), dateTime12FormatShort);%0A    %7D%0A%0A    @Test%0A    public void parsingNaturalTimes_time12FormatLong_equals() throws IllegalValueException %7B%0A        DateTime dateTime12FormatLong = DateTimeParser.getDateTimeFromString(time12FormatLong);%0A        assertEquals(genStandardTime(), dateTime12FormatLong);%0A    %7D%0A%0A    @Test%0A    public void parsingNaturalTimes_timeNaturalTime_equals() throws IllegalValueException %7B%0A        DateTime dateTimeNatural = DateTimeParser.getDateTimeFromString(timeNatural);%0A        assertEquals(genStandardTime(), dateTimeNatural);%0A    %7D%0A%0A    */%0A%0A
 %7D%0A//

update DateTimeParserTest