Skip to content

Commit 222006d

Browse files
committed
Merge branch A-MoreErrorHandling to master branch
2 parents 9fb27d5 + 2d353b7 commit 222006d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/phuc/util/ErrorHandler.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public class ErrorHandler {
3434
/** Error message for invalid direction format */
3535
public static final String ERROR_DIRECTION_FORMAT =
3636
"Please enter ascending or descending for the sorted order (×͡×)";
37+
/** Error message for invalid start date after end date */
38+
public static final String ERROR_DAY_FORMAT =
39+
"Oh no! The start date cannot be after the end date. "
40+
+ "Please make sure your event starts before it ends :)";
41+
/** Error message for invalid start date equal end date */
42+
public static final String ERROR_DAY_FORMAT_EQUALS =
43+
"Oh no! The start date and end date cannot be the same. :(";
3744

3845
/**
3946
* Handles the cases where the direction is not in the right format.
@@ -126,6 +133,14 @@ public static String[] validateEventFormat(String eventInStringForm) throws Phuc
126133
throw new PhucException(ERROR_EVENT_FORMAT);
127134
}
128135

136+
if (validateAndParseDateTime(startDate).isAfter(validateAndParseDateTime(endDate))) {
137+
throw new PhucException(ERROR_DAY_FORMAT);
138+
}
139+
140+
if (validateAndParseDateTime(startDate).isEqual(validateAndParseDateTime(endDate))) {
141+
throw new PhucException(ERROR_DAY_FORMAT_EQUALS);
142+
}
143+
129144
String[] eventParts = new String[3];
130145
eventParts[0] = description;
131146
eventParts[1] = startDate;

0 commit comments

Comments
 (0)