diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index 496fd9d21f80..6581c60754df 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -12,7 +12,7 @@ public class Messages { public static final String MESSAGE_INVALID_TASK_DISPLAYED_INDEX = "The task index provided is invalid"; public static final String MESSAGE_COMPLETED_TASK = "The task has completed already..."; public static final String MESSAGE_TASKS_LISTED_OVERVIEW = "%1$d tasks listed!"; - public static final String MESSAGE_ZERO_HOURS_COMPLETION = "It is impossible to complete it in 0 hours ;)"; + public static final String MESSAGE_ZERO_HOURS_COMPLETION = "It is impossible to complete it in less than 1 hour ;)"; public static final String MESSAGE_INVALID_DEADLINE = "The date selected does not exist"; public static final String MESSAGE_DEADLINE_CONTAINS_ILLEGAL_CHARACTERS = "Input deadline " + "contains illegal characters"; diff --git a/src/main/java/seedu/address/storage/XmlAdaptedTask.java b/src/main/java/seedu/address/storage/XmlAdaptedTask.java index ab28a714f0e6..4ada3cfed2f4 100644 --- a/src/main/java/seedu/address/storage/XmlAdaptedTask.java +++ b/src/main/java/seedu/address/storage/XmlAdaptedTask.java @@ -1,5 +1,6 @@ package seedu.address.storage; +import static seedu.address.commons.core.Messages.MESSAGE_ZERO_HOURS_COMPLETION; import static seedu.address.commons.util.StringUtil.isNonZeroUnsignedInteger; import static seedu.address.logic.parser.ParserUtil.MESSAGE_INVALID_HOURS; @@ -184,7 +185,7 @@ public Task toModelType() throws IllegalValueException { // Check validity of completed num of hours final int modelCompletedNumOfHours; - if (!completedNumOfHours.equals("-1") || Integer.valueOf(completedNumOfHours) < -1) { + if (completedNumOfHours == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "Number of hours taken to complete")); } else { @@ -195,6 +196,12 @@ public Task toModelType() throws IllegalValueException { //Boolean cannot be checked for null --> if (isCompleted == null) final boolean modelIsCompleted = isCompleted; + if (isCompleted && modelCompletedNumOfHours <= 0) { + throw new IllegalValueException(MESSAGE_ZERO_HOURS_COMPLETION); + } else if (!isCompleted && modelCompletedNumOfHours > 0) { + throw new IllegalValueException("Task is not completed yet ..."); + } + // Check validity of Milestones final List milestoneEntries = new ArrayList(); if (milestonelist != null && !milestonelist.isEmpty()) {