package tars.model.task;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import tars.commons.exceptions.IllegalValueException;

/**
 * Represents a Task's datetime in tars.
 */
public class DateTime {
    public static final String MESSAGE_NAME_CONSTRAINTS = "Task datetime should be spaces or alphanumeric characters";

    private LocalDateTime startDate;
    private LocalDateTime endDate;

    public String startDateString;
    public String endDateString;
    
    /**
     * Default constructor
     */
    public DateTime() {}

    /**
     * Validates given task dateTime.
     *
     * @throws DateTimeParseException
     *             if given dateTime string is invalid.
     * @throws IllegalDateException
     *             end date occurring before start date.
     */
    public DateTime(String startDate, String endDate) throws DateTimeParseException, IllegalDateException {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm");

        this.endDate = LocalDateTime.parse(endDate, formatter);
        this.endDateString = endDate;

        if (startDate != null) {
            this.startDate = LocalDateTime.parse(startDate, formatter);
            this.startDateString = startDate;
            if (this.endDate.isBefore(this.startDate) || this.endDate.isEqual(this.startDate)) {
                throw new IllegalDateException("End dateTime should be after start dateTime.");
            }
        }


    }

    public void setStartDate(LocalDateTime startDate) {
        this.startDate = startDate;
    }

    public void setEndDate(LocalDateTime endDate) {
        this.endDate = endDate;
    }

    @Override
    public String toString() {
        if (this.startDate == null) {
            return endDateString;
        } else {
            return startDateString + " to " + endDateString;
        }
    }

    /**
     * Signals an error caused by end date occurring before start date
     */
    public class IllegalDateException extends IllegalValueException {
        public IllegalDateException(String message) {
            super(message);
        }
    }
}

@@ -19,16 +19,52 @@
 .task;%0A%0A
+import java.time.DateTimeException;%0A
 import j
@@ -154,38 +154,29 @@
 .format.
-DateTimeParseException
+ResolverStyle
 ;%0A%0Aimpor
@@ -701,37 +701,32 @@
 @throws DateTime
-Parse
 Exception%0A     *
@@ -718,35 +718,16 @@
 xception
-%0A     *            
  if give
@@ -795,27 +795,8 @@
 tion
-%0A     *            
  end
@@ -891,16 +891,28 @@
 endDate)
+%0A           
  throws 
@@ -923,13 +923,8 @@
 Time
-Parse
 Exce
@@ -1012,39 +1012,110 @@
 tter
-.ofPattern(%22dd/MM/yyyy HHmm%22);%0A
+%0A                .ofPattern(%22d/M/uuuu HHmm%22)%0A                .withResolverStyle(ResolverStyle.STRICT);
 %0A   
@@ -1582,18 +1582,16 @@
       %7D%0A
-%0A%0A
     %7D%0A%0A 
@@ -2246,10 +2246,15 @@
 %7D%0A    %7D%0A
+    %0A
 %7D%0A

Change DateTimeParseException to DateTimeException Add strict rule when parsing the date to check if the date is valid