Untitled
user_8477608
plain_text
13 days ago
1.2 kB
3
Indexable
private LocalDateTime calculateFinalShiftEndTime(LocalDateTime requestTime) { // Find the next shift (not the current one) ShiftProperties currentShift = this.findShiftProperties(requestTime.toLocalTime().getHour()); if (currentShift == null) { throw new RuntimeException("No shift properties found for the given time"); } ShiftProperties otherShift = shiftPropertiesRepo.findByShiftNotAndDeletedFalse(currentShift.getShift()) .orElseThrow(() -> new RuntimeException("No next shift found")); LocalDate requestDate = requestTime.toLocalDate(); // If the shift is the starting shift, return the next shift's end time if (currentShift.isStatingShift()) { if (currentShift.getToHour().isBefore(currentShift.getFromHour())) { // Shift crosses midnight (Night Shift) return requestDate.atTime(otherShift.getToHour()); } else { // Regular shift return requestDate.atTime(otherShift.getToHour()).plusDays(1); } } else { return requestDate.atTime(currentShift.getToHour()); } }
Editor is loading...
Leave a Comment