<commit_before>package seedu.task.model.task;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.nlp.PrettyTimeParser;

import com.google.api.services.calendar.model.EventDateTime;

import seedu.task.commons.exceptions.IllegalValueException;

/**
 * Represents a Task's date in KIT. Guarantees: immutable; is valid as declared
 * in {@link #isValidDate(String)}
 */
public class Date {

    public static final String MESSAGE_DATE_CONSTRAINTS = "Date format invalid, try dates like,"
                                                        + " tomorrow at 5pm or 4th April."
                                                        + " Check that Month is before date,"
                                                        + " MM/DD/YY or MM-DD-YY";
    public static final String DEFAULT_DATE = "DEFAULT_DATE";
    private final java.util.Date value;
    private static PrettyTimeParser pretty = new PrettyTimeParser();
    private String extractedFrom = "";

    //@@author A0140063X
    public Date() {
        this.value = null;
    }

    //@@author A0140063X
    /**
     * Validates given date.
     *
     * @throws IllegalValueException
     *             if given date string is invalid.
     */
    public Date(String date) throws IllegalValueException {
        assert date != null;
        String trimmedDate = date.trim();

        if (date.equals(DEFAULT_DATE) || trimmedDate.equals("")) {
            this.value = null;

        } else {
            if (!isValidDate(trimmedDate)) {
                throw new IllegalValueException(MESSAGE_DATE_CONSTRAINTS);
            }

            List<java.util.Date> dates = pretty.parse(date);
            Calendar cal = Calendar.getInstance();
            cal.setTime(dates.get(0));
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
            long time = cal.getTimeInMillis();

            this.value = new java.util.Date(time);
            extractedFrom += date;
        }
    }

    //@@author A0140063X
    public Date(EventDateTime eventDateTime) {
        if (eventDateTime == null) {
            this.value = null;
            return;
        }

        if (eventDateTime.getDateTime() != null) {
            this.value = new java.util.Date(eventDateTime.getDateTime().getValue());
        } else if (eventDateTime.getDate() != null) {
            this.value = new java.util.Date(eventDateTime.getDate().getValue());
        } else {
            this.value = null;
        }
    }

    //@@author A0140063X
    /**
     * Returns true if a given string is a valid date.
     */
    public static boolean isValidDate(String input) {
        List<java.util.Date> dates = pretty.parse(input);
//        List<java.util.Date> dates = pretty.parse("remark");
        if (dates.isEmpty()) {
            return false;
        } else {
            return true;
        }
    }

    //@@author A0140063X
    public java.util.Date getDateValue() {
        return this.value;
    }

    //@@author A0140063X
    public boolean isNull() {
        return this.value == null;
    }

    //@@author A0140063X
    /**<commit_msg>Deleted some unused and unnecessary comments in Date class.<commit_after>package seedu.task.model.task;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.nlp.PrettyTimeParser;

import com.google.api.services.calendar.model.EventDateTime;

import seedu.task.commons.exceptions.IllegalValueException;

/**
 * Represents a Task's date in KIT. Guarantees: immutable; is valid as declared
 * in {@link #isValidDate(String)}
 */
public class Date {

    public static final String MESSAGE_DATE_CONSTRAINTS = "Date format invalid, try dates like,"
                                                        + " tomorrow at 5pm or 4th April."
                                                        + " Check that Month is before date,"
                                                        + " MM/DD/YY or MM-DD-YY";
    public static final String DEFAULT_DATE = "DEFAULT_DATE";
    private final java.util.Date value;
    private static PrettyTimeParser pretty = new PrettyTimeParser();
    private String extractedFrom = "";

    //@@author A0140063X
    public Date() {
        this.value = null;
    }

    //@@author A0140063X
    /**
     * Validates given date.
     *
     * @throws IllegalValueException
     *             if given date string is invalid.
     */
    public Date(String date) throws IllegalValueException {
        assert date != null;
        String trimmedDate = date.trim();

        if (date.equals(DEFAULT_DATE) || trimmedDate.equals("")) {
            this.value = null;

        } else {
            if (!isValidDate(trimmedDate)) {
                throw new IllegalValueException(MESSAGE_DATE_CONSTRAINTS);
            }

            List<java.util.Date> dates = pretty.parse(date);
            Calendar cal = Calendar.getInstance();
            cal.setTime(dates.get(0));
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
            long time = cal.getTimeInMillis();

            this.value = new java.util.Date(time);
            extractedFrom += date;
        }
    }

    //@@author A0140063X
    public Date(EventDateTime eventDateTime) {
        if (eventDateTime == null) {
            this.value = null;
            return;
        }

        if (eventDateTime.getDateTime() != null) {
            this.value = new java.util.Date(eventDateTime.getDateTime().getValue());
        } else if (eventDateTime.getDate() != null) {
            this.value = new java.util.Date(eventDateTime.getDate().getValue());
        } else {
            this.value = null;
        }
    }

    //@@author A0140063X
    /**
     * Returns true if a given string is a valid date.
     */
    public static boolean isValidDate(String input) {
        List<java.util.Date> dates = pretty.parse(input);
        if (dates.isEmpty()) {
            return false;
        } else {
            return true;
        }
    }

    //@@author A0140063X
    public java.util.Date getDateValue() {
        return this.value;
    }

    //@@author A0140063X
    public boolean isNull() {
        return this.value == null;
    }

    //@@author A0140063X
    /**
{'fraction_non_alphanumeric': 0.10788123736981191, 'fraction_numerical': 0.016788434633918856, 'mean_word_length': 1.8813255709807435, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2641963', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1736, 'n_words': 431}