Skip to content

Commit 1477f66

Browse files
committed
Added exception if /to before /from
1 parent 9192a89 commit 1477f66

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/main/java/duke/parser/Parser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
import static duke.ui.MessageConstants.MESSAGE_ERROR_EMPTY_DESCRIPTION;
1818
import static duke.ui.MessageConstants.MESSAGE_ERROR_FROM_TIME_MISSING;
1919
import static duke.ui.MessageConstants.MESSAGE_ERROR_TO_TIME_MISSING;
20+
import static duke.ui.MessageConstants.MESSAGE_ERROR_TO_BEFORE_FROM;
2021
import static duke.ui.MessageConstants.MESSAGE_ERROR_DEADLINE_BY;
2122
import static duke.ui.MessageConstants.MESSAGE_ERROR_COMMAND;
2223
import static duke.ui.MessageConstants.MESSAGE_ERROR_FIND_MISSING;
2324

25+
2426
import static duke.parser.TaskConstants.DEADLINE;
2527
import static duke.parser.TaskConstants.EVENT;
2628
import static duke.parser.TaskConstants.TODO;
@@ -136,6 +138,10 @@ public static AddEventCommand parseEventCommand(String commandRawInput) throws D
136138
throw new DukeException(MESSAGE_ERROR_TO_TIME_MISSING);
137139
}
138140

141+
if (toPos < fromPos) {
142+
throw new DukeException(MESSAGE_ERROR_TO_BEFORE_FROM);
143+
}
144+
139145
//get the task name
140146
String description = commandRawInput.substring(0,fromPos).trim();
141147

src/main/java/duke/ui/MessageConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class MessageConstants {
2727
public static final String MESSAGE_ERROR_EMPTY_DESCRIPTION = "☹ OOPS!!! The description of a task cannot be empty.";
2828
public static final String MESSAGE_ERROR_FROM_TIME_MISSING = "☹ OOPS!!! The /from time of an event cannot be empty.";
2929
public static final String MESSAGE_ERROR_TO_TIME_MISSING = "☹ OOPS!!! The /to time of an event cannot be empty.";
30+
public static final String MESSAGE_ERROR_TO_BEFORE_FROM = "☹ OOPS!!! The /from time of an event must be typed before the /to time.";
3031
public static final String MESSAGE_ERROR_DEADLINE_BY = "☹ OOPS!!! The /by time of a deadline cannot be empty.";
3132
public static final String MESSAGE_ERROR_FIND_MISSING = "☹ OOPS!!! The word you are searching for cannot be empty.";
3233
public static final String MESSAGE_ERROR_FILE_CREATION = "☹ OOPS!!! Error creating file.";

0 commit comments

Comments
 (0)