File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import static popo .utils .Messages .MESSAGE_EMPTY_DESCRIPTION ;
44import static popo .utils .Messages .MESSAGE_ENTER_COMMAND ;
5+ import static popo .utils .Messages .MESSAGE_ENTER_POSITIVE_DURATION ;
56import static popo .utils .Messages .MESSAGE_FOLLOW_USAGE ;
67import static popo .utils .Messages .MESSAGE_INDICATE_TASK ;
78import static popo .utils .Messages .MESSAGE_INVALID_COMMAND ;
@@ -211,6 +212,9 @@ private Command parseArgumentsForDuration(String arguments) throws NoDescription
211212 String durationTaskName = durationInputArr [0 ].strip ();
212213 String durationString = durationInputArr [1 ].strip ();
213214 long amount = Long .parseLong (durationString );
215+ if (amount < 0 ) {
216+ throw new InvalidDescriptionException (MESSAGE_ENTER_POSITIVE_DURATION );
217+ }
214218 Duration duration = Duration .of (amount , unit );
215219 return new DurationCommand (durationTaskName , duration );
216220 } catch (NumberFormatException ex ) {
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ public class Messages {
77 // Messages to show to user upon a parse error.
88 public static final String MESSAGE_EMPTY_DESCRIPTION = "The description of a task cannot be empty." ;
99 public static final String MESSAGE_ENTER_COMMAND = "Please enter a command." ;
10+ public static final String MESSAGE_ENTER_POSITIVE_DURATION = "Please enter a positive duration!" ;
1011 public static final String MESSAGE_FOLLOW_USAGE = "Please follow the usage as shown below:" ;
1112 public static final String MESSAGE_INDICATE_TASK = "Please indicate a task number." ;
1213 public static final String MESSAGE_INVALID_COMMAND = "OOPS!!! I'm sorry, but I don't know what that means :-(" ;
You can’t perform that action at this time.
0 commit comments