Skip to content

Commit

Permalink
Merge pull request #260 from andrefoo/master
Browse files Browse the repository at this point in the history
Bug fix: Exclusive end time for FreeTime
  • Loading branch information
kristayeo authored Nov 8, 2023
2 parents f0853ad + 9166bbb commit 1a5c04b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FreeTime implements Comparable<FreeTime> {
+ "Day is case-insensitive.";

public static final String VALIDATION_REGEX = "^(?i)(monday|tuesday|wednesday|thursday|friday|saturday|sunday) "
+ "([01]?\\d|2[0-3])(00|30) ([01]?\\d|2[0-3])(00|30)$"; //format: (case-insensitive) day 2359 2359
+ "([01]?\\d|2[0-3])(00|30) (([01]?\\d|2[0-3])(00|30)|(2400))$";

public final String freeTimeString;
private final DayOfWeek day;
Expand Down Expand Up @@ -47,6 +47,9 @@ public FreeTime(String freeTime) {
* Returns true if a given string is a valid tag name.
*/
public static boolean isValidFreeTime(String test) {
if (!test.matches(VALIDATION_REGEX)) {
System.out.println("YOUR INPUT DOESN'T WORK" + test);
}
return test.matches(VALIDATION_REGEX);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public static Module newModule(String unparsedInput) throws IllegalValueExceptio

// Check for valid number of parts
if (parts.length != 4) {
throw new IllegalArgumentException("Invalid module input format. Expected: NAME DAY HHMM HHMM");
String errorMsg = "Invalid module input format. Expected: NAME DAY HHMM HHMM" + MESSAGE_CONSTRAINTS;
throw new IllegalArgumentException(errorMsg);
}

String name = parts[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public List<FreeTime> getThisWeeksFreeTime() {
startSlot = slot;
} else if (timeSlots[day][slot] && startSlot != -1) {
// End of a free time slot
freeTimes.add(createFreeTime(day, startSlot, slot - 1));
freeTimes.add(createFreeTime(day, startSlot, slot));
startSlot = -1;
}
}
if (startSlot != -1) {
freeTimes.add(createFreeTime(day, startSlot, 47)); // The entire day is free.
freeTimes.add(createFreeTime(day, startSlot, 48)); // The entire day is free.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class TimeBlock implements Comparable<TimeBlock> {
+ "Day is case-insensitive. The start time must be before the end time.";

public static final String VALIDATION_REGEX = "^(?i)(monday|tuesday|wednesday|thursday|friday|saturday|sunday) "
+ "([01]?\\d|2[0-3])(00|30) ([01]?\\d|2[0-3])(00|30)$"; //format: (case-insensitive) day 2359 2359
+ "([01]?\\d|2[0-3])(00|30) (([01]?\\d|2[0-3])(00|30)|(2400))$"; //format: (case-insensitive) day 2359 2359

private String timeBlockString;
private final DayOfWeek day;
Expand Down

0 comments on commit 1a5c04b

Please sign in to comment.