1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
public static List<Shift> generateShifts(LocalDate startDate, LocalDate endDate, List<ShiftType> shiftTypes) { List<Shift> shifts = new ArrayList<>();
LocalDate currentDate = startDate; while (currentDate.isBefore(endDate) || currentDate.isEqual(endDate)) { for (ShiftType shiftType : shiftTypes) { LocalDateTime shiftStart = LocalDateTime.of(currentDate, shiftType.getStart()); LocalDateTime shiftEnd = shiftType.getEnd().isBefore(shiftType.getStart()) ? LocalDateTime.of(currentDate.plusDays(1), shiftType.getEnd()) : LocalDateTime.of(currentDate, shiftType.getEnd());
shifts.add(new Shift(shiftStart, shiftEnd, shiftType.getShiftName())); } currentDate = currentDate.plusDays(1); } shifts.sort(Comparator.comparing(Shift::getStart)); return shifts; }
|