diff --git a/src/main/java/seedu/flexitrack/model/ModelManager.java b/src/main/java/seedu/flexitrack/model/ModelManager.java index 03276e1c55c2..40f59ae687f9 100644 --- a/src/main/java/seedu/flexitrack/model/ModelManager.java +++ b/src/main/java/seedu/flexitrack/model/ModelManager.java @@ -204,7 +204,7 @@ public String toString() { } } - //TODO: + private class DateQualifier implements Qualifier { private String keyWords; private String dateInfo; @@ -217,33 +217,16 @@ private class DateQualifier implements Qualifier { .replace(ListCommand.LIST_NEXT_WEEK_COMMAND, "").replace(ListCommand.LIST_NEXT_MONTH_COMMAND, "").trim(); } + //TODO: need to refactor @Override public boolean run(ReadOnlyTask task) { - boolean willBeShown=true; - - if (keyWords.contains(ListCommand.LIST_FUTURE_COMMAND)) { - if (task.getIsTask()){ - willBeShown = DateTimeInfo.isInTheFuture(task.getDueDate()); - } else if (task.getIsEvent()){ - willBeShown = DateTimeInfo.isInTheFuture(task.getEndTime()); - }else { - willBeShown = !task.getIsDone(); - } - } else if (keyWords.contains(ListCommand.LIST_PAST_COMMAND)){ - if (task.getIsTask()){ - willBeShown = DateTimeInfo.isInThePast(task.getDueDate()); - } else { - willBeShown = DateTimeInfo.isInThePast(task.getEndTime()); - } - } else if (keyWords.contains(ListCommand.LIST_LAST_COMMAND) || keyWords.contains(ListCommand.LIST_NEXT_COMMAND)){ - willBeShown = DateTimeInfo.withInTheDuration(keyWords,task); - } else if (!dateInfo.equals("")){ - willBeShown = DateTimeInfo.isOnTheDate(keyWords, task); - } + + boolean willBeShown = isTaskGoingToBeShown(task); if (willBeShown==false){ return false; } + if (keyWords.contains(ListCommand.LIST_UNMARK_COMMAND)){ return !task.getIsDone(); } else if (keyWords.contains(ListCommand.LIST_MARK_COMMAND)){ @@ -253,11 +236,29 @@ public boolean run(ReadOnlyTask task) { return willBeShown; } + + /** + * @param task + * @param willBeShown + * @return + */ + private boolean isTaskGoingToBeShown(ReadOnlyTask task) { + if (keyWords.contains(ListCommand.LIST_FUTURE_COMMAND)) { + if (task.getIsNotFloatingTask()){ + return DateTimeInfo.isInTheFuture(DateTimeInfo.getCurrentTimeInString(), task.getEndingTimeOrDueDate()); + }else { + return !task.getIsDone(); + } + } else if (keyWords.contains(ListCommand.LIST_PAST_COMMAND)){ + return DateTimeInfo.isInThePast(DateTimeInfo.getCurrentTimeInString(), task.getEndingTimeOrDueDate()); + } else if (keyWords.contains(ListCommand.LIST_LAST_COMMAND) || keyWords.contains(ListCommand.LIST_NEXT_COMMAND)){ + return DateTimeInfo.withInTheDuration(keyWords, task, DateTimeInfo.getCurrentTimeInString().toString()); + } else { + return DateTimeInfo.isOnTheDate(dateInfo, task); + } + // if (!dateInfo.equals("")) + } -// @Override -// public String toString() { -// return "name=" + String.join(", ", dateKeyWords); -// } } diff --git a/src/main/java/seedu/flexitrack/model/task/DateTimeInfo.java b/src/main/java/seedu/flexitrack/model/task/DateTimeInfo.java index 31e79e38b427..206e5a9dfa84 100644 --- a/src/main/java/seedu/flexitrack/model/task/DateTimeInfo.java +++ b/src/main/java/seedu/flexitrack/model/task/DateTimeInfo.java @@ -9,17 +9,18 @@ import seedu.flexitrack.commons.exceptions.IllegalValueException; import seedu.flexitrack.logic.commands.ListCommand; +//@@author A0127686R /** * Represents a DateTimeInfo class in FlexiTrack */ public class DateTimeInfo { public static final String MESSAGE_DATETIMEINFO_CONSTRAINTS = "Invalid time inputed. Please check your spelling!"; - public static final boolean DUE_DATE_OR_START_TIME = true; - public static final boolean END_TIME = false; + public static final String MESSAGE_FROM_IS_AFTER_TO = "Please check the timing inputed! The given starting time is after the ending time."; + private static final Pattern TIME_TYPE_DATA_ARGS_FORMAT = Pattern.compile("(?.+)"); - private static final String MESSAGE_FROM_IS_AFTER_TO = "Please check the timing inputed! The given starting time is after the ending time."; private static final int AVERAGE_DAYS_IN_A_MONTH = 30; - private static final int DAYS_IN_A_WEEK = 7; + private static final int DAYS_IN_A_WEEK = 7; + private static final boolean FAIL_DUE_TO_EXCEPTION = false; private String setTime; @@ -31,16 +32,26 @@ public DateTimeInfo(String givenTime) throws IllegalValueException { * Set the setTime (DateGroup object) as the date inputed by the user * * @param givenTime + * @throws IllegalValueException */ public void setDateGroupTime(String givenTime) throws IllegalValueException { assert givenTime != null; final Matcher matcher = TIME_TYPE_DATA_ARGS_FORMAT.matcher(givenTime.trim()); matcher.matches(); - DateTimeInfoParser parsedTiming = new DateTimeInfoParser(matcher.group("info")); - this.setTime = parsedTiming.getParsedTimingInfo(); - formatTiming(parsedTiming.isInferred()); + DateTimeInfoParser parsedTiming; + try { + parsedTiming = new DateTimeInfoParser(matcher.group("info")); + this.setTime = parsedTiming.getParsedTimingInfo(); + formatTiming(parsedTiming.isInferred()); + } catch (IllegalValueException e) { + throw new IllegalValueException (MESSAGE_DATETIMEINFO_CONSTRAINTS); + } } + /** + * Change the format of the timing saved in setTime + * @param inferred + */ private void formatTiming(boolean inferred) { if (inferred) { setTime = getDateMonthYear() + " 07:59"; @@ -49,6 +60,10 @@ private void formatTiming(boolean inferred) { } } + /** + * Extract the month, date and year of a particular date + * @return timing in MMM DD YYYY format + */ private String getDateMonthYear() { return setTime.substring(5, 12) + setTime.substring(25, 29); } @@ -116,6 +131,12 @@ public static String durationOfTheEvent(String startingTime, String endingTime) return durationBetweenTwoTiming(startingTime,endingTime); } + /** + * prepare variables needed to calculate the duration between two timing + * @param startingTime + * @param endingTime + * @return the duration of the event in a string + */ private static String durationBetweenTwoTiming(String startingTime, String endingTime) { int years = yearsOfTheEvent(startingTime, endingTime); int months = monthsOfTheEvent(startingTime, endingTime); @@ -126,6 +147,15 @@ private static String durationBetweenTwoTiming(String startingTime, String endin return combineDuratingOfEvent(years, months, days, hours, minutes); } + /** + * Calculate the duration of the event + * @param years + * @param months + * @param days + * @param hours + * @param minutes + * @return the duration of the event in a string + */ private static String combineDuratingOfEvent(int years, int months, int days, int hours, int minutes) { String duration1 = new String(""); @@ -212,7 +242,7 @@ private static int daysOfTheEvent(String startingTime, String endingTime) { } /** - * Calculate the day difference between the end and the start + * Calculate the year difference between the end and the start * * @param startingTime * @param endingTime @@ -240,7 +270,7 @@ private static int monthsOfTheEvent(String startingTime, String endingTime) { @Override public String toString() { - return setTime.substring(0, 17); + return setTime; } @Override @@ -255,120 +285,195 @@ public int hashCode() { return setTime.hashCode(); } + /** + * @return true if the date not specified; + */ public boolean isDateNull() { return this.setTime.equals("Feb 29 2000 00:00"); } + /** + * If the time is inferred, replace "07:59" with "16:59" + */ public void isEndTimeInferred() { if (setTime.substring(12, 17).equals("07:59")) { setTime = setTime.substring(0, 12) + "16:59"; } } - public static boolean isInTheFuture(DateTimeInfo Date) { + /** + * Process the task if the task is in the future + * @param timeNow + * @param Date + * @return true if the timing timeNow is after the timing Date + */ + public static boolean isInTheFuture(DateTimeInfo timeNow, DateTimeInfo Date) { String result = MESSAGE_FROM_IS_AFTER_TO; - try { - result = durationBetweenTwoTiming(new DateTimeInfo ("now").toString(),Date.toString()); - } catch (IllegalValueException e) { - e.printStackTrace(); - } + result = durationBetweenTwoTiming(timeNow.toString(),Date.toString()); return !result.equals(MESSAGE_FROM_IS_AFTER_TO); } - public static boolean isInThePast(DateTimeInfo Date) { - String result = MESSAGE_FROM_IS_AFTER_TO; - try { - result = durationBetweenTwoTiming(Date.toString(),new DateTimeInfo ("now").toString()); - } catch (IllegalValueException e) { - e.printStackTrace(); - } - return !result.equals(MESSAGE_FROM_IS_AFTER_TO); + /** + * Process the task if the task is in the past + * @param timeNow + * @param Date + * @return true if the timing timeNow is before the timing Date + */ + public static boolean isInThePast(DateTimeInfo timeNow, DateTimeInfo Date) { + return isInTheFuture(Date,timeNow); } - - public static boolean isOnTheDate(String keyWords, ReadOnlyTask task) { - String dateInfo = keyWords.replace(ListCommand.LIST_MARK_COMMAND, "").replace(ListCommand.LIST_UNMARK_COMMAND, "").trim(); + + /** + * Prepare the keyword and process if the task is within the specified date. + * @param keyWords + * @param task + * @return + */ + public static boolean isOnTheDate(String dateInfo, ReadOnlyTask task) { try { dateInfo = new DateTimeInfo (dateInfo).toString().substring(0,11); } catch (IllegalValueException e) { - e.printStackTrace(); + new IllegalValueException (MESSAGE_DATETIMEINFO_CONSTRAINTS); } - if ( task.getDueDate().toString().contains(dateInfo) || task.getEndTime().toString().contains(dateInfo) - || task.getStartTime().toString().contains(dateInfo)){ - return true; - } - return false; + return isTaskOnTheSpecifiedDate(task, dateInfo); } - public static boolean withInTheDuration(String keyWords, ReadOnlyTask task) { - - String dateNow=null; - boolean timeDifference=false; + /** + * Process if the task given has any relation with the dateInfo. + * For a task relation is defined as the due date is the dateInfo date. + * For an event, the event duration (inclusive the starting and the ending date) is within the specified DateInfo date. + * @param task + * @param dateInfo + * @return true if the task has anything to do with the day of interest + */ + private static boolean isTaskOnTheSpecifiedDate(ReadOnlyTask task, String dateInfo) { + return task.getDueDate().toString().contains(dateInfo) || task.getEndTime().toString().contains(dateInfo) + || task.getStartTime().toString().contains(dateInfo) + || isTaskAnEventPassingThisDate(task, dateInfo); + } + /** + * Process the data if it the task is a event and it is passing through the date specified. + * @param task + * @param dateInfo + * @return true if a task is an event and the day interest is within the starting date and the ending date + */ + private static boolean isTaskAnEventPassingThisDate(ReadOnlyTask task, String dateInfo) { + if (!task.getIsEvent()){ + return false; + } + DateTimeInfo dateSpecified; try { - dateNow = new DateTimeInfo ("now").toString(); + dateSpecified = new DateTimeInfo (dateInfo); + return isInTheFuture(task.getStartTime(), dateSpecified) && isInTheFuture(dateSpecified, task.getEndTime()); } catch (IllegalValueException e) { - e.printStackTrace(); + new IllegalValueException (MESSAGE_DATETIMEINFO_CONSTRAINTS); } - + return FAIL_DUE_TO_EXCEPTION; + } + + /** + * Process if the a task specified is with in the duration stated. + * @param keyWords + * @param task + * @return true if the date is within the duration + */ + public static boolean withInTheDuration(String keyWords, ReadOnlyTask task, String dateNow) { + boolean isWithInTime = false; if ( keyWords.contains(ListCommand.LIST_LAST_WEEK_COMMAND) ){ - if (task.getIsTask()){ - timeDifference = isDurationLessThanSpecified(dateNow, task.getDueDate().toString(), DAYS_IN_A_WEEK); - } else if (task.getIsEvent()){ - timeDifference = isDurationLessThanSpecified(dateNow, task.getEndTime().toString(), DAYS_IN_A_WEEK); - } else { - return false; - } + return isNotFloatingTaskAndWithinTheTime(task, dateNow, -DAYS_IN_A_WEEK); } else if ( keyWords.contains(ListCommand.LIST_LAST_MONTH_COMMAND) ){ - if (task.getIsTask()){ - timeDifference = isDurationLessThanSpecified(dateNow, task.getDueDate().toString(), AVERAGE_DAYS_IN_A_MONTH); - } else if (task.getIsEvent()){ - timeDifference = isDurationLessThanSpecified(dateNow, task.getEndTime().toString(), AVERAGE_DAYS_IN_A_MONTH); - } else { - return false; - } + return isNotFloatingTaskAndWithinTheTime(task, dateNow, -AVERAGE_DAYS_IN_A_MONTH); } else if ( keyWords.contains(ListCommand.LIST_NEXT_MONTH_COMMAND) ){ - if (task.getIsTask()){ - timeDifference = isDurationLessThanSpecified(task.getDueDate().toString(), dateNow, AVERAGE_DAYS_IN_A_MONTH); - } else if (task.getIsEvent()){ - timeDifference = isDurationLessThanSpecified(task.getEndTime().toString(), dateNow, AVERAGE_DAYS_IN_A_MONTH); - } else { - return false; - } + return isNotFloatingTaskAndWithinTheTime(task, dateNow, AVERAGE_DAYS_IN_A_MONTH); } else if ( keyWords.contains(ListCommand.LIST_NEXT_WEEK_COMMAND) ){ - if (task.getIsTask()){ - timeDifference = isDurationLessThanSpecified(task.getDueDate().toString(), dateNow, DAYS_IN_A_WEEK); - } else if (task.getIsEvent()){ - timeDifference = isDurationLessThanSpecified(task.getEndTime().toString(), dateNow, DAYS_IN_A_WEEK); - } else { - return false; - } + return isNotFloatingTaskAndWithinTheTime(task, dateNow, DAYS_IN_A_WEEK); + } + return isWithInTime; + } + + /** + * Process if the task given is either a deadline task or an event within the specified timing + * @param task + * @param dateNow + * @param expectedDays + * @return true if the task is not a floating task and it is within the specified timing + */ + private static boolean isNotFloatingTaskAndWithinTheTime(ReadOnlyTask task, String dateNow, int expectedDays) { + if (task.getIsNotFloatingTask()){ + return isTaskWithInTheDuration(task, dateNow, expectedDays); + } else { + return false; + } + } + + /** + * Process if a deadline task or an event is within the duration specified. + * @param task + * @param dateNow + * @param expectedDays + * @return true if the task is within the stated duration + */ + private static boolean isTaskWithInTheDuration(ReadOnlyTask task, String dateNow, int expectedDays) { + boolean isTimeWithinExpectedTime=false; + if (task.getIsNotFloatingTask()){ + isTimeWithinExpectedTime = isTimeDifferenceLessThanSpecified(dateNow, + task.getStartingTimeOrDueDate().toString(), expectedDays); + } + return isTimeWithinExpectedTime; + } + + /** + * Provide an easy access to the current timing in String + * @return String of the current time MMM DD YYYY HH:MM format. + */ + public static DateTimeInfo getCurrentTimeInString() { + DateTimeInfo dateNow = null; + try { + dateNow = new DateTimeInfo ("now"); + } catch (IllegalValueException e) { + new IllegalValueException (MESSAGE_DATETIMEINFO_CONSTRAINTS); } - return timeDifference; + return dateNow; } - private static boolean isDurationLessThanSpecified(String startTime, String endTime, int maxDuration) { + /** + * Process if the two given time is less than the time duration. + * @param startTime + * @param endTime + * @param limitTimeDuration + * @return true if the time Difference is less than specified + */ + private static boolean isTimeDifferenceLessThanSpecified(String startTime, String endTime, int limitTimeDuration) { + if (limitTimeDuration<0){ + limitTimeDuration = limitTimeDuration*(-1); + return isTimeDifferenceLessThanSpecified (endTime, startTime, limitTimeDuration); + } + int years = yearsOfTheEvent(startTime, endTime); int months = monthsOfTheEvent(startTime, endTime); int days = daysOfTheEvent(startTime, endTime); int hours = hoursOfTheEvent(startTime, endTime); - + if (hours < 0) { hours = Math.floorMod(hours, 24); days=days-1; } if (days < 0) { - return false; + days = Math.floorMod(days, 30); + months=months-1; } - if (months < 0 || months>0) { + if (months < 0 || months>1) { return false; } if (years < 0 || years > 0) { return false; } - if(days < maxDuration || (months == 1 && days == 0)){ + if(days <= limitTimeDuration && months==0){ return true; - } - else { + } else if ( limitTimeDuration==AVERAGE_DAYS_IN_A_MONTH && months==1){ + return true; + } else { return false; } } diff --git a/src/main/java/seedu/flexitrack/model/task/ReadOnlyTask.java b/src/main/java/seedu/flexitrack/model/task/ReadOnlyTask.java index 2e7fd94e4e2e..858cac91beb3 100644 --- a/src/main/java/seedu/flexitrack/model/task/ReadOnlyTask.java +++ b/src/main/java/seedu/flexitrack/model/task/ReadOnlyTask.java @@ -12,17 +12,16 @@ public interface ReadOnlyTask { Name getName(); DateTimeInfo getDueDate(); - DateTimeInfo getStartTime(); - DateTimeInfo getEndTime(); + DateTimeInfo getStartingTimeOrDueDate(); + DateTimeInfo getEndingTimeOrDueDate(); boolean getIsTask(); - boolean getIsEvent(); - boolean getIsDone(); - + boolean getIsNotFloatingTask(); + /** * The returned TagList is a deep copy of the internal TagList, changes on * the returned list will not affect the person's internal tags. @@ -70,4 +69,6 @@ default String tagsString() { } } + + } diff --git a/src/main/java/seedu/flexitrack/model/task/Task.java b/src/main/java/seedu/flexitrack/model/task/Task.java index 6d41ed99b418..0830a79d1793 100644 --- a/src/main/java/seedu/flexitrack/model/task/Task.java +++ b/src/main/java/seedu/flexitrack/model/task/Task.java @@ -157,4 +157,25 @@ public void setIsTask(Boolean bool) { public void setIsEvent(Boolean bool) { this.isEvent = bool; } + + public boolean getIsNotFloatingTask(){ + return (this.isEvent || this.isTask); + } + + public DateTimeInfo getStartingTimeOrDueDate(){ + if (this.getIsTask()){ + return this.getDueDate(); + } else { + return this.getStartTime(); + } + } + + public DateTimeInfo getEndingTimeOrDueDate(){ + if (this.getIsTask()){ + return this.getDueDate(); + } else { + return this.getEndTime(); + } + } + } diff --git a/src/test/java/seedu/flexitrack/model/task/DateTimeInfoTest.java b/src/test/java/seedu/flexitrack/model/task/DateTimeInfoTest.java new file mode 100644 index 000000000000..1f708b2b1bd7 --- /dev/null +++ b/src/test/java/seedu/flexitrack/model/task/DateTimeInfoTest.java @@ -0,0 +1,155 @@ +package seedu.flexitrack.model.task; + +import org.junit.Before; +import org.junit.Test; +import seedu.flexitrack.model.task.DateTimeInfo; +import seedu.flexitrack.commons.exceptions.IllegalValueException; + +import static org.junit.Assert.*; +import static seedu.flexitrack.model.task.DateTimeInfo.MESSAGE_FROM_IS_AFTER_TO; + +public class DateTimeInfoTest { + + private DateTimeInfo testTime1; + private DateTimeInfo testTime2; + + @Before + public void setup() { + testTime1 = null; + testTime2 = null; + } + +// @Test +// public void emptyInput_returnsIncorrect() { +// final String[] emptyInputs = { "", " ", "\n \n" }; +// final String resultMessage = String.format(MESSAGE_DATETIMEINFO_CONSTRAINTS); +// DateTimeInfoAndAssertIncorrectWithMessage(resultMessage, emptyInputs); +// } + + @Test + public void ValidInputWithNoSpecificHoursAndMinutes_returnsDate() { + final String validInput = "3 July 2018"; + final String expectedSetTime = "Jul 03 2018 07:59"; + DateTimeInfoAndAssertCorrect(validInput, expectedSetTime); + } + + @Test + public void ValidInputWithSpecificHours_returnsDate() { + final String validInput = "22 january 2017 4pm"; + final String expectedSetTime = "Jan 22 2017 16:00"; + DateTimeInfoAndAssertCorrect(validInput, expectedSetTime); + } + + @Test + public void RelaxValidInputWithNoSpecificHoursAndMinutes_returnsDate() { + final String validInput = "mon"; + final String expectedSetTime = "Oct 31 2016 07:59"; + DateTimeInfoAndAssertCorrect(validInput, expectedSetTime); + } + + @Test + public void RelaxValidInputWithSpecificHours_returnsDate() { + final String validInput = "tuesday 10am"; + final String expectedSetTime = "Nov 01 2016 10:00"; + DateTimeInfoAndAssertCorrect(validInput, expectedSetTime); + } + + @Test + public void RelativeValidInputWithNoSpecificHoursAndMinutes_returnsDate() { + final String validInput = "next month"; + final String expectedSetTime = "Nov 26 2016 07:59"; + DateTimeInfoAndAssertCorrect(validInput, expectedSetTime); + } + + @Test + public void RelativeValidInputWithSpecificHours_returnsDate() { + final String validInput = "last month"; + final String expectedSetTime = "Sep 26 2016 07:59"; + DateTimeInfoAndAssertCorrect(validInput, expectedSetTime); + } + + @Test + public void IsDateNull_DateIsNull_True() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Feb 29 2000 00:00"); + assertTrue(testTime1.isDateNull()); + } + + @Test + public void IsDateNull_DateIsNotNull_False() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Feb 29 2001 00:00"); + assertTrue(!testTime1.isDateNull()); + } + + @Test + public void durationOfTheEvent_DurationIsPositive_7Days3hours() throws IllegalValueException { + testTime1 = new DateTimeInfo ("May 12 2017 07:00"); + testTime2 = new DateTimeInfo ("May 19 2017 10:00"); + String expected = "Duration of the event is: 7 days 3 hours."; + assertTrue(DateTimeInfo.durationOfTheEvent(testTime1.toString(), testTime2.toString()).equals(expected)); + } + + @Test + public void durationOfTheEvent_DurationIsNegative_Message() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Aug 12 2017 07:00"); + testTime2 = new DateTimeInfo ("Mar 19 2017 10:00"); + String expected = MESSAGE_FROM_IS_AFTER_TO; + assertTrue(DateTimeInfo.durationOfTheEvent(testTime1.toString(), testTime2.toString()).equals(expected)); + } + + @Test + public void durationOfTheEvent_ExactSameTiming_Message() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Jun 26 2017 07:00"); + testTime2 = new DateTimeInfo ("Jun 26 2017 07:00"); + String expected = "Event starts and end at the same time."; + assertTrue(DateTimeInfo.durationOfTheEvent(testTime1.toString(), testTime2.toString()).equals(expected)); + } + + @Test + public void isInTheFuture_validInput_True() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Jun 26 2017 07:00"); + testTime2 = new DateTimeInfo ("Jun 26 2018 07:00"); + assertTrue(DateTimeInfo.isInTheFuture(testTime1, testTime2)); + } + + @Test + public void isInTheFuture_invalidInput_False() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Jun 26 2017 07:00"); + testTime2 = new DateTimeInfo ("Jun 26 2018 07:00"); + assertTrue(!DateTimeInfo.isInTheFuture(testTime2, testTime1)); + } + + @Test + public void isInTheFuture_sameInput_True() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Jun 26 2017 07:00"); + assertTrue(DateTimeInfo.isInTheFuture(testTime1, testTime1)); + } + + @Test + public void isInThePast_validInput_True() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Jun 26 2017 07:00"); + testTime2 = new DateTimeInfo ("Jun 26 2018 07:00"); + assertTrue(DateTimeInfo.isInThePast(testTime2, testTime1)); + } + + @Test + public void isInThePast_invalidInput_False() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Jun 26 2017 07:00"); + testTime2 = new DateTimeInfo ("Jun 26 2018 07:00"); + assertTrue(!DateTimeInfo.isInThePast(testTime1, testTime2)); + } + + @Test + public void isInThePast_sameInput_True() throws IllegalValueException { + testTime1 = new DateTimeInfo ("Jun 26 2017 07:00"); + assertTrue(DateTimeInfo.isInThePast(testTime1, testTime1)); + } + + private void DateTimeInfoAndAssertCorrect(String validInput, String expectedSetTime) { + try { + testTime1 = new DateTimeInfo (validInput); + } catch (IllegalValueException e) { + } + assertTrue(expectedSetTime.equals(testTime1.toString())); + } + +} diff --git a/src/test/java/seedu/flexitrack/testutil/TestTask.java b/src/test/java/seedu/flexitrack/testutil/TestTask.java index 4e41181ce52d..0dde85e3c084 100644 --- a/src/test/java/seedu/flexitrack/testutil/TestTask.java +++ b/src/test/java/seedu/flexitrack/testutil/TestTask.java @@ -159,4 +159,27 @@ public static String getUnMarkCommand(int taskToUnMark) { return sb.toString(); } + @Override + public boolean getIsNotFloatingTask() { + return !( this.isEvent || this.isTask ); + } + + @Override + public DateTimeInfo getStartingTimeOrDueDate(){ + if (this.getIsTask()){ + return this.getDueDate(); + } else { + return this.getStartTime(); + } + } + + @Override + public DateTimeInfo getEndingTimeOrDueDate(){ + if (this.getIsTask()){ + return this.getDueDate(); + } else { + return this.getEndTime(); + } + } + }