Example usage for org.joda.time Interval getEnd

List of usage examples for org.joda.time Interval getEnd

Introduction

In this page you can find the example usage for org.joda.time Interval getEnd.

Prototype

public DateTime getEnd() 

Source Link

Document

Gets the end of this time interval, which is exclusive, as a DateTime.

Usage

From source file:net.sourceforge.fenixedu.domain.Lesson.java

License:Open Source License

public boolean overlaps(final Interval interval) {
    if (wasFinished()) {
        return false;
    }/* w  ww .  j a v  a2  s.  c o m*/
    final YearMonthDay startDateToSearch = getLessonStartDay();
    if (startDateToSearch == null) {
        return false;
    }
    final YearMonthDay endDateToSearch = getLessonEndDay();
    if (endDateToSearch == null) {
        return false;
    }
    final DateTime intervalStart = interval.getStart();
    if (intervalStart.isAfter(endDateToSearch.toDateTimeAtMidnight().plusDays(1))) {
        return false;
    }
    final DateTime intervalEnd = interval.getEnd();
    if (intervalEnd.isBefore(startDateToSearch.toDateTimeAtMidnight())) {
        return false;
    }
    final HourMinuteSecond b = getBeginHourMinuteSecond();
    final HourMinuteSecond e = getEndHourMinuteSecond();
    for (final YearMonthDay yearMonthDay : getAllValidLessonDatesWithoutInstancesDates(startDateToSearch,
            endDateToSearch)) {
        final DateTime start = new DateTime(yearMonthDay.getYear(), yearMonthDay.getMonthOfYear(),
                yearMonthDay.getDayOfMonth(), b.getHour(), b.getMinuteOfHour(), b.getSecondOfMinute(), 0);
        if (start.isAfter(intervalEnd)) {
            continue;
        }
        final DateTime end = new DateTime(yearMonthDay.getYear(), yearMonthDay.getMonthOfYear(),
                yearMonthDay.getDayOfMonth(), e.getHour(), e.getMinuteOfHour(), e.getSecondOfMinute(), 0);
        if (end.isBefore(intervalStart)) {
            continue;
        }
        return true;
    }
    return false;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

License:Open Source License

private boolean isAllIntervalIn(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(), 0);
    HourMinuteSecond intervalEnd = new HourMinuteSecond(interval.getEnd().getHourOfDay(),
            interval.getEnd().getMinuteOfHour(), 0);

    for (YearMonthDay day : allLessonDates) {
        if (intervalStartDate.isEqual(intervalEndDate)) {
            if (day.isEqual(intervalStartDate) && !intervalBegin.isBefore(getBeginHourMinuteSecond())
                    && !intervalEnd.isAfter(getEndHourMinuteSecond())) {
                return true;
            }//from w ww .  j a v  a  2s  .c  om
        }
    }
    return false;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

License:Open Source License

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;
            }//  w  w  w  . j a  va  2  s  .co m
        } else {
            if ((day.isAfter(intervalStartDate) && day.isBefore(intervalEndDate))
                    || day.isEqual(intervalStartDate) && !getEndHourMinuteSecond().isBefore(intervalBegin)
                    || (day.isEqual(intervalEndDate) && !getBeginHourMinuteSecond().isAfter(intervalEnd))) {
                return true;
            }
        }
    }
    return false;
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonContractSituation.java

License:Open Source License

public boolean overlaps(final Interval interval) {
    Interval situationInterval = getInterval();
    return getBeginDate() != null && ((situationInterval != null && situationInterval.overlaps(interval))
            || (situationInterval == null && !getBeginDate().isAfter(interval.getEnd().toLocalDate())));
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonContractSituation.java

License:Open Source License

public boolean betweenDates(Interval interval) {
    if (isValid()) {
        if (getEndDate() == null) {
            return !getBeginDate().isAfter(interval.getEnd().toLocalDate());
        }//from  ww w  . j a  va 2 s  .c  o m
        return getInterval().overlaps(interval);
    }
    return false;
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonContractSituation.java

License:Open Source License

public int getDaysInInterval(Interval intervalWithNextPeriods) {
    LocalDate beginDate = getBeginDate().isBefore(intervalWithNextPeriods.getStart().toLocalDate())
            ? intervalWithNextPeriods.getStart().toLocalDate()
            : getBeginDate();/*from   www. j  a  v  a2  s. c o  m*/
    LocalDate endDate = getEndDate() == null
            || getEndDate().isAfter(intervalWithNextPeriods.getEnd().toLocalDate())
                    ? intervalWithNextPeriods.getEnd().toLocalDate()
                    : getEndDate();
    return Days.daysBetween(beginDate, endDate).getDays();
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalCategory.java

License:Open Source License

public boolean overlaps(final Interval interval) {
    Interval categoryInterval = getInterval();
    return getBeginDate() != null && ((categoryInterval != null && categoryInterval.overlaps(interval))
            || (categoryInterval == null && !getBeginDate().isAfter(interval.getEnd().toLocalDate())));
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalData.java

License:Open Source License

public ProfessionalRegime getDominantProfessionalRegime(GiafProfessionalData giafProfessionalData,
        Interval interval, CategoryType categoryType) {
    PersonProfessionalRegime dominantPersonProfessionalRegime = null;
    int dominantPersonProfessionalRegimeDays = 0;
    if (giafProfessionalData != null) {
        for (final PersonProfessionalRegime regime : giafProfessionalData.getValidPersonProfessionalRegimes()) {
            if (regime.overlaps(interval) && (regime.getProfessionalRegime().getCategoryType() == null
                    || regime.getProfessionalRegime().getCategoryType().equals(categoryType))) {
                int thisRegimeDays = regime.getDaysInInterval(interval);
                if (dominantPersonProfessionalRegimeDays < thisRegimeDays
                        || (dominantPersonProfessionalRegimeDays == thisRegimeDays
                                && (dominantPersonProfessionalRegime == null
                                        || regime.isAfter(dominantPersonProfessionalRegime)))) {
                    dominantPersonProfessionalRegime = regime;
                    dominantPersonProfessionalRegimeDays = thisRegimeDays;
                }/*w  ww . ja va 2 s  . c  om*/
            }
        }
        if (dominantPersonProfessionalRegime == null) {
            if (giafProfessionalData.getProfessionalRegimeDate() != null && !giafProfessionalData
                    .getProfessionalRegimeDate().isAfter(interval.getEnd().toLocalDate())) {
                return giafProfessionalData.getProfessionalRegime();
            }
        }
    }
    return dominantPersonProfessionalRegime == null ? null
            : dominantPersonProfessionalRegime.getProfessionalRegime();
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalRegime.java

License:Open Source License

public boolean overlaps(final Interval interval) {
    Interval regimeInterval = getInterval();
    return getBeginDate() != null && ((regimeInterval != null && regimeInterval.overlaps(interval))
            || (regimeInterval == null && !getBeginDate().isAfter(interval.getEnd().toLocalDate())));
}

From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalRegime.java

License:Open Source License

public int getDaysInInterval(Interval interval) {
    LocalDate beginDate = getBeginDate().isBefore(interval.getStart().toLocalDate())
            ? interval.getStart().toLocalDate()
            : getBeginDate();/*from w w w.j a v  a2  s . c o m*/
    LocalDate endDate = getEndDate() == null || getEndDate().isAfter(interval.getEnd().toLocalDate())
            ? interval.getEnd().toLocalDate()
            : getEndDate();
    return Days.daysBetween(beginDate, endDate).getDays();
}