Java Code Examples for org.joda.time.LocalDate.getDayOfYear()

The following are Jave code examples for showing how to use getDayOfYear() of the org.joda.time.LocalDate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: exam   File: CalendarController.java   Source Code and License Vote up 5 votes
/**
 * @return all intervals that fall within provided working hours
 */
private static Iterable<Interval> allSlots(Iterable<ExamRoom.OpeningHours> openingHours, ExamRoom room, LocalDate date) {
    Collection<Interval> intervals = new ArrayList<>();
    List<ExamStartingHour> startingHours = room.getExamStartingHours();
    if (startingHours.isEmpty()) {
        // Default to 1 hour slots that start at the hour
        startingHours = createDefaultStartingHours(room.getLocalTimezone());
    }
    Collections.sort(startingHours);
    DateTime now = DateTime.now().plusMillis(DateTimeZone.forID(room.getLocalTimezone()).getOffset(DateTime.now()));
    for (ExamRoom.OpeningHours oh : openingHours) {
        int tzOffset = oh.getTimezoneOffset();
        DateTime instant = now.getDayOfYear() == date.getDayOfYear() ? now : oh.getHours().getStart();
        DateTime slotEnd = oh.getHours().getEnd();
        DateTime beginning = nextStartingTime(instant, startingHours, tzOffset);
        while (beginning != null) {
            DateTime nextBeginning = nextStartingTime(beginning.plusMillis(1), startingHours, tzOffset);
            if (beginning.isBefore(oh.getHours().getStart())) {
                beginning = nextBeginning;
                continue;
            }
            if (nextBeginning != null && !nextBeginning.isAfter(slotEnd)) {
                intervals.add(new Interval(beginning.minusMillis(tzOffset), nextBeginning.minusMillis(tzOffset)));
                beginning = nextBeginning;
            } else if (beginning.isBefore(slotEnd)) {
                // We have some spare time in the end, take it as well
                intervals.add(new Interval(beginning.minusMillis(tzOffset), slotEnd.minusMillis(tzOffset)));
                break;
            } else {
                break;
            }
        }
    }
    return intervals;
}