Skip to content
Snippets Groups Projects
Commit dae20ae7 authored by Rafi Zereselasie (raz070)'s avatar Rafi Zereselasie (raz070)
Browse files

Added a clause to the add shift method that checks the availability and makes...

Added a clause to the add shift method that checks the availability and makes sure that the start is later than the end.
parent e1759d2b
No related branches found
No related tags found
No related merge requests found
...@@ -244,15 +244,21 @@ public class Model { ...@@ -244,15 +244,21 @@ public class Model {
if (id <= 0){ if (id <= 0){
return "Invalid ID"; return "Invalid ID";
} }
if (start < 0 || end < 0 || start > 2359 || end > 2359){ if (start < 0 || end < 0 || end > 2359 || start >= end){
return "Invalid start or end time"; return "Invalid start or end time";
} }
int[] dayOfTheWeekAvailability = this.employees.get(id).getAvailabilityForDay(LocalDate.parse(date)
.getDayOfWeek().getValue()%7);
if (dayOfTheWeekAvailability[0] > start || dayOfTheWeekAvailability[1] < start || dayOfTheWeekAvailability[1] < end) {
return "Shift time conflicts with employees availability";
}
for (Shift shift : getShiftsByDay(date)){ for (Shift shift : getShiftsByDay(date)){
if (shift.getEmployeeID() == id){ if (shift.getEmployeeID() == id){
int otherShiftStart = Integer.parseInt(shift.getStart().toLocalTime().toString().replace(":", "")); int otherShiftStart = Integer.parseInt(shift.getStart().toLocalTime().toString().replace(":", ""));
int otherShiftEnd = Integer.parseInt(shift.getEnd().toLocalTime().toString().replace(":", "")); int otherShiftEnd = Integer.parseInt(shift.getEnd().toLocalTime().toString().replace(":", ""));
if (start <= otherShiftEnd && !(end <= otherShiftStart)){ if (start <= otherShiftEnd && !(end <= otherShiftStart)){
return "Shift time conflict for employee"; return "Shift time conflict with existing shift";
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment