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

The following examples show how to use org.joda.time.YearMonthDay#plusDays() . 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: ViewEventSpaceOccupationsBean.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ViewEventSpaceOccupationsBean(YearMonthDay day, Space allocatableSpace) {

        setAllocatableSpace(allocatableSpace);

        if (day != null) {
            setYear(new Partial(DateTimeFieldType.year(), day.getYear()));
            setMonth(new Partial(DateTimeFieldType.monthOfYear(), day.getMonthOfYear()));

            YearMonthDay monday = day.toDateTimeAtMidnight().withDayOfWeek(MONDAY_IN_JODA_TIME).toYearMonthDay();
            if ((monday.getMonthOfYear() < day.getMonthOfYear()) || (monday.getYear() < day.getYear())) {
                monday = monday.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
            }

            setDay(monday);
        }
    }
 
Example 2
Source File: MonthMondayDaysProvider.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object provide(Object source, Object currentValue) {

    List<YearMonthDay> result = new ArrayList<YearMonthDay>();
    ViewEventSpaceOccupationsBean bean = (ViewEventSpaceOccupationsBean) source;
    Partial year = bean.getYear();
    Partial month = bean.getMonth();

    if (month != null && year != null) {

        int monthNumber = month.get(DateTimeFieldType.monthOfYear());
        int yearNumber = year.get(DateTimeFieldType.year());

        YearMonthDay firstDayOfMonth = new YearMonthDay(yearNumber, monthNumber, 1);
        YearMonthDay monday = firstDayOfMonth.toDateTimeAtMidnight().withDayOfWeek(MONDAY_IN_JODA_TIME).toYearMonthDay();

        if ((monday.getMonthOfYear() < monthNumber) || (monday.getYear() < yearNumber)) {
            monday = monday.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
        }

        while (monday.getMonthOfYear() == monthNumber) {
            result.add(monday);
            monday = monday.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
        }
    }

    return result;
}
 
Example 3
Source File: Lesson.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private YearMonthDay getValidBeginDate(YearMonthDay startDate) {
    YearMonthDay lessonBegin =
            startDate.toDateTimeAtMidnight().withDayOfWeek(getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat())
                    .toYearMonthDay();
    if (lessonBegin.isBefore(startDate)) {
        lessonBegin = lessonBegin.plusDays(NUMBER_OF_DAYS_IN_WEEK);
    }
    return lessonBegin;
}
 
Example 4
Source File: Lesson.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private SortedSet<YearMonthDay> getAllValidLessonDatesWithoutInstancesDates(YearMonthDay startDateToSearch,
        YearMonthDay endDateToSearch) {

    SortedSet<YearMonthDay> result = new TreeSet<YearMonthDay>();
    startDateToSearch = startDateToSearch != null ? getValidBeginDate(startDateToSearch) : null;

    if (!wasFinished() && startDateToSearch != null && endDateToSearch != null && !startDateToSearch.isAfter(endDateToSearch)) {
        Space lessonCampus = getLessonCampus();
        final int dayIncrement =
                getFrequency() == FrequencyType.BIWEEKLY ? FrequencyType.WEEKLY.getNumberOfDays() : getFrequency()
                        .getNumberOfDays();
        boolean shouldAdd = true;
        while (true) {
            if (isDayValid(startDateToSearch, lessonCampus)) {
                if (getFrequency() != FrequencyType.BIWEEKLY || shouldAdd) {
                    if (!isHoliday(startDateToSearch, lessonCampus)) {
                        result.add(startDateToSearch);
                    }
                }
                shouldAdd = !shouldAdd;
            }
            startDateToSearch = startDateToSearch.plusDays(dayIncrement);
            if (startDateToSearch.isAfter(endDateToSearch)) {
                break;
            }
        }
    }
    return result;
}
 
Example 5
Source File: EventSpaceOccupation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static List<Interval> generateEventSpaceOccupationIntervals(YearMonthDay begin, final YearMonthDay end,
        final HourMinuteSecond beginTime, final HourMinuteSecond endTime, final FrequencyType frequency,
        final DiaSemana diaSemana, final Boolean dailyFrequencyMarkSaturday, final Boolean dailyFrequencyMarkSunday,
        final YearMonthDay startDateToSearch, final YearMonthDay endDateToSearch) {

    List<Interval> result = new ArrayList<Interval>();
    begin = getBeginDateInSpecificWeekDay(diaSemana, begin);

    if (frequency == null) {
        if (!begin.isAfter(end)
                && (startDateToSearch == null || (!end.isBefore(startDateToSearch) && !begin.isAfter(endDateToSearch)))) {
            result.add(createNewInterval(begin, end, beginTime, endTime));
            return result;
        }
    } else {
        int numberOfDaysToSum = frequency.getNumberOfDays();
        while (true) {
            if (begin.isAfter(end)) {
                break;
            }
            if (startDateToSearch == null || (!begin.isBefore(startDateToSearch) && !begin.isAfter(endDateToSearch))) {

                Interval interval = createNewInterval(begin, begin, beginTime, endTime);

                if (!frequency.equals(FrequencyType.DAILY)
                        || ((dailyFrequencyMarkSaturday || interval.getStart().getDayOfWeek() != SATURDAY_IN_JODA_TIME) && (dailyFrequencyMarkSunday || interval
                                .getStart().getDayOfWeek() != SUNDAY_IN_JODA_TIME))) {

                    result.add(interval);
                }
            }
            begin = begin.plusDays(numberOfDaysToSum);
        }
    }
    return result;
}
 
Example 6
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 7
Source File: EventSpaceOccupation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static YearMonthDay getBeginDateInSpecificWeekDay(DiaSemana diaSemana, YearMonthDay begin) {
    if (diaSemana != null) {
        YearMonthDay newBegin =
                begin.toDateTimeAtMidnight().withDayOfWeek(diaSemana.getDiaSemanaInDayOfWeekJodaFormat()).toYearMonthDay();
        if (newBegin.isBefore(begin)) {
            begin = newBegin.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
        } else {
            begin = newBegin;
        }
    }
    return begin;
}
 
Example 8
Source File: LessonInstance.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private YearMonthDay findNextPossibleDateAfter(YearMonthDay day, Lesson lesson) {
    for (YearMonthDay lessonDay : lesson.getAllLessonDatesWithoutInstanceDates()) {
        if (lessonDay.isAfter(day)) {
            return lessonDay;
        }
    }
    return lesson.isBiWeeklyOffset() ? day.plusDays(8) : day.plusDays(1);
}