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

The following examples show how to use org.joda.time.YearMonthDay#isBefore() . 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: RoomSiteComponentBuilder.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void getWrittenEvaluationRoomOccupations(List<InfoObject> infoShowOccupations,
        final YearMonthDay weekStartYearMonthDay, final YearMonthDay weekEndYearMonthDay,
        final Collection<WrittenEvaluation> writtenEvaluations) {

    if (writtenEvaluations != null) {

        for (WrittenEvaluation writtenEvaluation : writtenEvaluations) {

            final YearMonthDay evaluationDate = writtenEvaluation.getDayDateYearMonthDay();

            if (!evaluationDate.isBefore(weekStartYearMonthDay) && !evaluationDate.isAfter(weekEndYearMonthDay)) {

                if (writtenEvaluation instanceof Exam) {
                    final Exam exam = (Exam) writtenEvaluation;
                    if (exam.isExamsMapPublished()) {
                        infoShowOccupations.add(InfoExam.newInfoFromDomain(exam));
                    }
                } else if (writtenEvaluation instanceof WrittenTest) {
                    final WrittenTest writtenTest = (WrittenTest) writtenEvaluation;
                    infoShowOccupations.add(InfoWrittenTest.newInfoFromDomain(writtenTest));
                }
            }
        }
    }
}
 
Example 2
Source File: Thesis.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setEnrolment(Enrolment enrolment) {
    final ExecutionDegree executionDegree = getExecutionDegree(enrolment);
    final YearMonthDay beginThesisCreationPeriod = executionDegree.getBeginThesisCreationPeriod();
    final YearMonthDay endThesisCreationPeriod = executionDegree.getEndThesisCreationPeriod();

    final YearMonthDay today = new YearMonthDay();
    if (beginThesisCreationPeriod == null || beginThesisCreationPeriod.isAfter(today)) {
        throw new DomainException("thesis.creation.not.allowed.because.out.of.period");
    }
    if (endThesisCreationPeriod != null && endThesisCreationPeriod.isBefore(today)) {
        throw new DomainException("thesis.creation.not.allowed.because.out.of.period");
    }

    CurricularCourse curricularCourse = enrolment.getCurricularCourse();
    if (!curricularCourse.isDissertation()) {
        throw new DomainException("thesis.enrolment.notDissertationEnrolment");
    }

    super.setEnrolment(enrolment);
}
 
Example 3
Source File: WrittenEvaluationSpaceOccupation.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<WrittenEvaluation> writtenEvaluations = getWrittenEvaluationsSet();

    for (WrittenEvaluation writtenEvaluation : writtenEvaluations) {
        YearMonthDay writtenEvaluationDay = writtenEvaluation.getDayDateYearMonthDay();
        if (startDateToSearch == null
                || (!writtenEvaluationDay.isBefore(startDateToSearch) && !writtenEvaluationDay.isAfter(endDateToSearch))) {

            result.add(createNewInterval(writtenEvaluationDay, writtenEvaluationDay,
                    writtenEvaluation.getBeginningDateHourMinuteSecond(), writtenEvaluation.getEndDateHourMinuteSecond()));
        }
    }
    return result;
}
 
Example 4
Source File: CycleCurriculumGroup.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public YearMonthDay calculateConclusionDate() {
    YearMonthDay result = super.calculateConclusionDate();

    if (getRegistration().getWasTransition()) {
        final ExecutionSemester firstBolonhaTransitionExecutionPeriod =
                ExecutionSemester.readFirstBolonhaTransitionExecutionPeriod();
        final YearMonthDay begin = firstBolonhaTransitionExecutionPeriod.getBeginDateYearMonthDay();

        if (result == null || result.isBefore(begin)) {
            result = begin;
        }
    }

    return result;
}
 
Example 5
Source File: OutboundMobilityCandidacyPeriod.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private OutboundMobilityCandidacyPeriod findPreviousPeriod() {
    OutboundMobilityCandidacyPeriod result = null;
    for (final ExecutionInterval interval : Bennu.getInstance().getExecutionIntervalsSet()) {
        for (final CandidacyPeriod candidacyPeriod : interval.getCandidacyPeriodsSet()) {
            if (candidacyPeriod instanceof OutboundMobilityCandidacyPeriod) {
                final OutboundMobilityCandidacyPeriod period = (OutboundMobilityCandidacyPeriod) candidacyPeriod;
                final YearMonthDay ymd = period.getExecutionInterval().getBeginDateYearMonthDay();
                if (ymd.isBefore(getExecutionInterval().getBeginDateYearMonthDay())
                        && (result == null || result.getExecutionInterval().getBeginDateYearMonthDay().isBefore(ymd))) {
                    result = period;
                }
            }
        }
    }
    return result;
}
 
Example 6
Source File: ExecutionSemester.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void checkDatesIntersection(YearMonthDay begin, YearMonthDay end) {
    List<InfoExecutionPeriod> infoExecutionPeriods = ReadExecutionPeriods.run();
    if (infoExecutionPeriods != null && !infoExecutionPeriods.isEmpty()) {

        Collections.sort(infoExecutionPeriods, InfoExecutionPeriod.COMPARATOR_BY_YEAR_AND_SEMESTER);

        for (InfoExecutionPeriod infoExecutionPeriod : infoExecutionPeriods) {
            ExecutionSemester executionSemester = infoExecutionPeriod.getExecutionPeriod();
            YearMonthDay beginDate = executionSemester.getBeginDateYearMonthDay();
            YearMonthDay endDate = executionSemester.getEndDateYearMonthDay();
            if (begin.isAfter(endDate) || end.isBefore(beginDate) || executionSemester.equals(this)) {
                continue;
            } else {
                throw new DomainException("error.ExecutionPeriod.intersection.dates");
            }
        }
    }
}
 
Example 7
Source File: RoomSiteComponentBuilder.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void getLessonInstanceOccupations(List<InfoObject> infoShowOccupations, YearMonthDay weekStartYearMonthDay,
        YearMonthDay weekEndYearMonthDay, Collection<LessonInstance> lessonInstances) {

    if (lessonInstances != null) {
        for (LessonInstance lessonInstance : lessonInstances) {
            final YearMonthDay lessonInstanceDay = lessonInstance.getDay();
            if (!lessonInstanceDay.isBefore(weekStartYearMonthDay) && !lessonInstanceDay.isAfter(weekEndYearMonthDay)) {
                InfoLessonInstance infoLessonInstance = new InfoLessonInstance(lessonInstance);
                infoShowOccupations.add(infoLessonInstance);
            }
        }
    }
}
 
Example 8
Source File: Lesson.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Lesson(DiaSemana diaSemana, Calendar inicio, Calendar fim, Shift shift, FrequencyType frequency,
        ExecutionSemester executionSemester, YearMonthDay beginDate, YearMonthDay endDate, Space room) {

    super();

    OccupationPeriod period = null;
    if (shift != null) {
        final ExecutionCourse executionCourse = shift.getExecutionCourse();
        GenericPair<YearMonthDay, YearMonthDay> maxLessonsPeriod = executionCourse.getMaxLessonsPeriod();
        if (beginDate == null || beginDate.isBefore(maxLessonsPeriod.getLeft())) {
            throw new DomainException("error.Lesson.invalid.begin.date");
        }
        if (endDate == null || endDate.isAfter(maxLessonsPeriod.getRight())) {
            throw new DomainException("error.invalid.new.date");
        }
        period = OccupationPeriod.createOccupationPeriodForLesson(executionCourse, beginDate, endDate);
    }

    setRootDomainObject(Bennu.getInstance());
    setDiaSemana(diaSemana);
    setInicio(inicio);
    setFim(fim);
    setShift(shift);
    setFrequency(frequency);
    setPeriod(period);

    checkShiftLoad(shift);

    if (room != null) {
        new LessonSpaceOccupation(room, this);
    }
}
 
Example 9
Source File: Lesson.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void edit(YearMonthDay newBeginDate, YearMonthDay newEndDate, DiaSemana diaSemana, Calendar inicio, Calendar fim,
        FrequencyType frequency, Boolean createLessonInstances, Space newRoom) {
    AccessControl.check(this, ResourceAllocationRolePredicates.checkPermissionsToManageLessons);

    if (newBeginDate != null && newEndDate != null && newBeginDate.isAfter(newEndDate)) {
        throw new DomainException("error.Lesson.new.begin.date.after.new.end.date");
    }

    GenericPair<YearMonthDay, YearMonthDay> maxLessonsPeriod = getShift().getExecutionCourse().getMaxLessonsPeriod();
    if (newBeginDate == null || newBeginDate.isBefore(maxLessonsPeriod.getLeft())) {
        throw new DomainException("error.Lesson.invalid.new.begin.date");
    }
    if (newEndDate == null || newEndDate.isAfter(maxLessonsPeriod.getRight())) {
        throw new DomainException("error.invalid.new.end.date");
    }

    refreshPeriodAndInstancesInEditOperation(newBeginDate, newEndDate, createLessonInstances, maxLessonsPeriod);

    if (wasFinished() && (getLessonSpaceOccupation() != null || !hasAnyLessonInstances())) {
        throw new DomainException("error.Lesson.empty.period");
    }

    setDiaSemana(diaSemana);
    setInicio(inicio);
    setFim(fim);
    setFrequency(frequency);

    checkShiftLoad(getShift());

    lessonSpaceOccupationManagement(newRoom);
}
 
Example 10
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 11
Source File: Lesson.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean contains(Interval interval, SortedSet<YearMonthDay> allLessonDates) {

        YearMonthDay intervalStartDate = interval.getStart().toYearMonthDay();
        YearMonthDay intervalEndDate = interval.getEnd().toYearMonthDay();

        HourMinuteSecond intervalBegin =
                new HourMinuteSecond(interval.getStart().getHourOfDay(), interval.getStart().getMinuteOfHour(), interval
                        .getStart().getSecondOfMinute());
        HourMinuteSecond intervalEnd =
                new HourMinuteSecond(interval.getEnd().getHourOfDay(), interval.getEnd().getMinuteOfHour(), interval.getEnd()
                        .getSecondOfMinute());

        for (YearMonthDay day : allLessonDates) {
            if (intervalStartDate.isEqual(intervalEndDate)) {
                if (day.isEqual(intervalStartDate) && !intervalBegin.isAfter(getEndHourMinuteSecond())
                        && !intervalEnd.isBefore(getBeginHourMinuteSecond())) {
                    return true;
                }
            } else {
                if ((day.isAfter(intervalStartDate) && day.isBefore(intervalEndDate)) || day.isEqual(intervalStartDate)
                        && !getEndHourMinuteSecond().isBefore(intervalBegin)
                        || (day.isEqual(intervalEndDate) && !getBeginHourMinuteSecond().isAfter(intervalEnd))) {
                    return true;
                }
            }
        }
        return false;
    }
 
Example 12
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 13
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 14
Source File: ExecutionSemester.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void editPeriod(YearMonthDay begin, YearMonthDay end) throws DomainException {
    if (begin == null || end == null || end.isBefore(begin)) {
        throw new DomainException("error.ExecutionPeriod.invalid.dates");
    }
    checkDatesIntersection(begin, end);
    setBeginDateYearMonthDay(begin);
    setEndDateYearMonthDay(end);
}
 
Example 15
Source File: GratuityTransaction.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isInsidePeriod(final YearMonthDay start, final YearMonthDay end) {
    final YearMonthDay date = getTransactionDateDateTime().toYearMonthDay();
    return !date.isBefore(start) && !date.isAfter(end);
}