package seedu.task.model.task;

import java.time.Instant;
import java.util.Date;
import java.util.List;

import org.ocpsoft.prettytime.nlp.PrettyTimeParser;

import seedu.task.commons.exceptions.IllegalValueException;

/**
 * Represents a Date and Time in the task list
 * Guarantees: immutable; is valid as declared in {@link #isValidDateTime(String)}
 */
public class DateTime {

    public static final String MESSAGE_DATETIME_CONSTRAINTS = "Date entered should be in a relatively standard form (e.g. in X hours, tomorrow, 20 Jan 2016, 5pm)";

    public final Instant value;

    /**
     * Validates given Date and Time entered by the user.
     *
     * @throws IllegalValueException if given phone string is invalid.
     */
    public DateTime(String dateTime) throws IllegalValueException {
        assert dateTime != null;
        List<Date> possibleDates = new PrettyTimeParser().parse(dateTime);
        if (!isValidDateTime(possibleDates)) {
            throw new IllegalValueException(MESSAGE_DATETIME_CONSTRAINTS);
        }
        
        this.value = possibleDates.get(0).toInstant();
    }

    /**
     * Returns true if a given string is a valid date/time that can be parsed
     * 
     * @param test output from date/time parser
     */
    public static boolean isValidDateTime(List<Date> test) {
        return !test.isEmpty() && (test.size() == 1);
    }

    @Override
    public String toString() {
        return value.toString();
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof DateTime// instanceof handles nulls
                && this.value.equals(((DateTime) other).value)); // state check
    }

    @Override
    public int hashCode() {
        return value.hashCode();
    }

}

@@ -96,16 +96,43 @@
 il.List;
+%0Aimport java.util.Optional;
 %0A%0Aimport
@@ -584,23 +584,33 @@
 c final 
+Optional%3C
 Instant
+%3E
  value;%0A
@@ -733,12 +733,16 @@
 ven 
-phon
+date/tim
 e st
@@ -867,16 +867,124 @@
 = null;%0A
+        if (dateTime.equals(%22%22)) %7B%0A            this.value = Optional.empty();%0A            return;%0A        %7D%0A
         
@@ -1212,16 +1212,28 @@
 value = 
+Optional.of(
 possible
@@ -1256,16 +1256,17 @@
 nstant()
+)
 ;%0A    %7D%0A
@@ -1598,22 +1598,50 @@
  return 
+(
 value.
+isPresent()) ? value.get().
 toString
@@ -1642,16 +1642,21 @@
 String()
+ : %22%22
 ;%0A    %7D%0A

Make underlying value of DateTime optional