Created
          May 2, 2017 10:46 
        
      - 
      
 - 
        
Save KDamir/a82ecac52fe8d0b990eb230d8a88e7f6 to your computer and use it in GitHub Desktop.  
    startOfDay
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private <W extends AbstractWorkingDay> List<WorkplaceAtTimeInterval> toTimeIntervals(List<W> workingDays, LocalDate date) { | |
| LocalDateTime branchStartDatetime = date.atTime(getTimetableDisplayStartTime()); | |
| LocalDateTime branchEndDatetime = date.atTime(getTimetableDisplayEndTime()); | |
| LocalDateTime from = getIsWorkdayEndsNextDay() ? branchStartDatetime.toLocalDate().atStartOfDay() : branchStartDatetime; | |
| LocalDateTime to = getIsWorkdayEndsNextDay() ? from.plusDays(1) : branchEndDatetime; | |
| List<WorkplaceAtTimeInterval> result = new ArrayList<>(); | |
| while (from.isBefore(to)) { | |
| final LocalDateTime counterValue = LocalDateTime.from(from); | |
| List<W> workingDaysAtTime = workingDays.stream().filter(wd -> wd.isDatetimeWithin(counterValue)).collect(Collectors.toList()); | |
| if (workingDaysAtTime.size() > 1) { | |
| throw new InvalidWorkingDayException(String.format("An error occured while trying to build week timetable;" + | |
| "\nAmbiguous schedule for workplace %s at dateTime %s", workingDaysAtTime.get(0).getWorkplaceId(), from)); | |
| } | |
| if (workingDaysAtTime.isEmpty()) { | |
| LocalDateTime nextWorkingDayStart = workingDays.stream() | |
| .map(AbstractWorkingDay::getStartLocalDatetime) | |
| .filter(localTime -> localTime.isAfter(counterValue)) | |
| .findFirst() | |
| .orElse(to); | |
| result.addAll(createEmptyAndBreakTimeIntervals(from, nextWorkingDayStart)); | |
| from = nextWorkingDayStart; | |
| } else { | |
| result.addAll(TimetableSlicer.sliceWorkingDayToWorkspaceInterval(from, to, workingDaysAtTime.get(0))); | |
| from = workingDaysAtTime.get(0).getEndLocalDatetime(); | |
| } | |
| } | |
| return result; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment