Java Code Examples for org.joda.time.YearMonthDay#toDateTime()

The following examples show how to use org.joda.time.YearMonthDay#toDateTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LessonInstanceSpaceOccupation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<Interval> getEventSpaceOccupationIntervals(YearMonthDay startDateToSearch, YearMonthDay endDateToSearch) {

    List<Interval> result = new ArrayList<Interval>();
    Collection<LessonInstance> lessonInstances = getLessonInstancesSet();

    DateTime startDateTime = startDateToSearch != null ? startDateToSearch.toDateTimeAtMidnight() : null;
    DateTime endDateTime = endDateToSearch != null ? endDateToSearch.toDateTime(new TimeOfDay(23, 59, 59)) : null;

    for (LessonInstance lessonInstance : lessonInstances) {
        if (startDateTime == null
                || (!lessonInstance.getEndDateTime().isBefore(startDateTime) && !lessonInstance.getBeginDateTime().isAfter(
                        endDateTime))) {

            result.add(new Interval(lessonInstance.getBeginDateTime(), lessonInstance.getEndDateTime()));
        }
    }
    return result;
}
 
Example 2
Source File: EventSpaceOccupation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected DateTime getInstant(boolean firstInstant, YearMonthDay begin, final YearMonthDay end,
        final HourMinuteSecond beginTime, final HourMinuteSecond endTime, final FrequencyType frequency,
        final DiaSemana diaSemana, final Boolean dailyFrequencyMarkSaturday, final Boolean dailyFrequencyMarkSunday) {

    DateTime instantResult = null;
    begin = getBeginDateInSpecificWeekDay(diaSemana, begin);

    if (frequency == null) {
        if (!begin.isAfter(end)) {
            if (firstInstant) {
                return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
            } else {
                return end.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
            }
        }
    } else {
        int numberOfDaysToSum = frequency.getNumberOfDays();
        while (true) {
            if (begin.isAfter(end)) {
                break;
            }

            DateTime intervalEnd = begin.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
            if (!frequency.equals(FrequencyType.DAILY)
                    || ((dailyFrequencyMarkSaturday || intervalEnd.getDayOfWeek() != SATURDAY_IN_JODA_TIME) && (dailyFrequencyMarkSunday || intervalEnd
                            .getDayOfWeek() != SUNDAY_IN_JODA_TIME))) {

                if (firstInstant) {
                    return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
                } else {
                    instantResult = intervalEnd;
                }
            }
            begin = begin.plusDays(numberOfDaysToSum);
        }
    }
    return instantResult;
}
 
Example 3
Source File: EventSpaceOccupation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected static Interval createNewInterval(YearMonthDay begin, YearMonthDay end, HourMinuteSecond beginTime,
        HourMinuteSecond endTime) {
    return new Interval(begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0)),
            end.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0)));
}