Example usage for org.joda.time LocalDate compareTo

List of usage examples for org.joda.time LocalDate compareTo

Introduction

In this page you can find the example usage for org.joda.time LocalDate compareTo.

Prototype

public int compareTo(ReadablePartial partial) 

Source Link

Document

Compares this partial with another returning an integer indicating the order.

Usage

From source file:org.kuali.kpme.core.location.validation.LocationValidation.java

License:Educational Community License

boolean validateRolePresent(List<LocationPrincipalRoleMemberBo> roleMembers, LocalDate effectiveDate) {
    boolean valid = true;
    boolean activeFlag = false;

    for (ListIterator<LocationPrincipalRoleMemberBo> iterator = roleMembers.listIterator(); iterator
            .hasNext();) {/* ww  w.  j  a v  a2s  .co m*/
        int index = iterator.nextIndex();
        RoleMemberBo roleMember = iterator.next();
        activeFlag |= roleMember.isActive();

        String prefix = "roleMembers[" + index + "].";

        if (roleMember.getActiveToDateValue() != null) {
            if (effectiveDate.compareTo(roleMember.getActiveToDate().toLocalDate()) >= 0
                    || roleMember.getActiveFromDateValue().compareTo(roleMember.getActiveToDateValue()) >= 0) {
                this.putFieldError(prefix + "expirationDate", "error.role.expiration");
                valid = false;
            }
        }
    }

    if (!activeFlag) {
        this.putGlobalError("role.required");
    }

    return valid & activeFlag;
}

From source file:org.kuali.kpme.core.util.ValidationUtils.java

License:Educational Community License

/**
 * Checks for date not more than one year in the future or current date
 * /*from   w  ww. ja va  2s  .c o m*/
 */

public static boolean validateOneYearFutureDate(LocalDate date) {
    LocalDate startDate = LocalDate.now().minusDays(1);
    LocalDate endDate = LocalDate.now().plusYears(1); // One year after the current date
    return date.compareTo(startDate) * date.compareTo(endDate) <= 0;
}

From source file:org.kuali.kpme.core.util.ValidationUtils.java

License:Educational Community License

/**
 * Checks for date not more than one year in the future and does not consider past date
 * /*w  ww  .  j a va  2s  .co m*/
 */

public static boolean validateOneYearFutureEffectiveDate(LocalDate date) {
    LocalDate startDate = LocalDate.now().plusYears(1); // One year after the current date
    return date.compareTo(startDate) <= 0;
}

From source file:org.kuali.kpme.core.util.ValidationUtils.java

License:Educational Community License

/**
 * Checks for date in the future//from   ww  w  .j  av a  2 s  .  c  o  m
 * 
 */

public static boolean validateFutureDate(LocalDate date) {
    LocalDate startDate = LocalDate.now();
    return date.compareTo(startDate) > 0;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

private boolean isDateAtPayCalInterval(LocalDate aDate, String earnInterval, String payCalName,
        Map<String, List<CalendarEntry>> aMap) {
    if (StringUtils.isNotEmpty(payCalName) && !aMap.isEmpty()
            && earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.PAY_CAL)) { // only used for ac earn interval == pay calendar
        List<CalendarEntry> entryList = aMap.get(payCalName);
        if (CollectionUtils.isNotEmpty(entryList)) {
            for (CalendarEntry anEntry : entryList) {
                // endPeriodDate of calendar entry is the beginning hour of the next day, so we need to substract one day from it to get the real end date
                LocalDate endDate = anEntry.getEndPeriodFullDateTime().toLocalDate().minusDays(1);
                if (aDate.compareTo(endDate) == 0) {
                    return true;
                }//  ww  w  . ja v  a 2  s  . c  o  m
            }
        }
    }
    return false;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

public List<AccrualCategoryRule> getAccrualCategoryRulesForDate(List<AccrualCategoryRule> acrList,
        String accrualCategoryId, LocalDate currentDate, LocalDate serviceDate) {
    List<AccrualCategoryRule> aList = new ArrayList<AccrualCategoryRule>();
    if (CollectionUtils.isNotEmpty(acrList)) {
        for (AccrualCategoryRule acr : acrList) {
            if (acr.getLmAccrualCategoryId().equals(accrualCategoryId)) {
                String uot = acr.getServiceUnitOfTime();
                int startTime = acr.getStart().intValue();
                int endTime = acr.getEnd().intValue();

                LocalDate startDate = serviceDate;
                LocalDate endDate = serviceDate;
                if (uot.equals("M")) { // monthly
                    startDate = startDate.plusMonths(startTime);
                    endDate = endDate.plusMonths(endTime).minusDays(1);
                } else if (uot.endsWith("Y")) { // yearly
                    startDate = startDate.plusYears(startTime);
                    endDate = endDate.plusYears(endTime).minusDays(1);
                }//  ww w . j a v a 2  s . c  om

                // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
                if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                    startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
                }
                if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                    endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
                }

                if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
                    aList.add(acr);
                }
            }
        }
    }
    return aList;
}

From source file:org.libreplan.business.calendars.entities.BaseCalendar.java

License:Open Source License

public CalendarData createNewVersionInsideIntersection(LocalDate startDate, LocalDate expiringDate) {
    for (CalendarData nextVersion : calendarDataVersions) {

        if ((nextVersion.getExpiringDate() == null)
                || (expiringDate.compareTo(nextVersion.getExpiringDate()) <= 0)) {

            int index = calendarDataVersions.indexOf(nextVersion);

            if (index > 0) {
                CalendarData prevVersion = calendarDataVersions.get(index - 1);

                if (newIntervalIncludeAnotherWorkWeek(startDate, expiringDate, prevVersion, nextVersion)) {
                    throw new IllegalArgumentException(
                            "the new work week includes a whole work week already exists");

                } else {
                    LocalDate prevExpiringDate = prevVersion.getExpiringDate();
                    LocalDate nextExpiringDate = nextVersion.getExpiringDate();
                    BaseCalendar oldParent = nextVersion.getParent();

                    if ((prevExpiringDate == null) || (startDate.compareTo(prevExpiringDate) > 0)) {
                        CalendarData prevCalendarData = CalendarData.create();
                        prevCalendarData.setExpiringDate(startDate);
                        prevCalendarData.setParent(oldParent);
                        resetDefaultCapacities(prevCalendarData);
                        calendarDataVersions.add(prevCalendarData);
                    } else {
                        prevVersion.setExpiringDate(startDate);
                    }/* ww  w. ja v  a2s  . c o  m*/

                    CalendarData newCalendarData = CalendarData.create();
                    newCalendarData.setExpiringDate(expiringDate);
                    calendarDataVersions.add(newCalendarData);

                    if ((nextExpiringDate != null) && (expiringDate.compareTo(nextExpiringDate) >= 0)) {
                        calendarDataVersions.remove(nextVersion);
                    }

                    Collections.sort(calendarDataVersions, CalendarData.BY_EXPIRING_DATE_COMPARATOR);

                    return newCalendarData;
                }
            } else {
                throw new IllegalArgumentException(
                        "Wrong start date : the new work week will be the first one, and the start date must be empty");
            }
        }
    }
    throw new IllegalArgumentException(
            "Wrong expiring date : the new work week will be the last one, and the expiring date must be empty");
}

From source file:org.libreplan.business.calendars.entities.BaseCalendar.java

License:Open Source License

public boolean newIntervalIncludeAnotherWorkWeek(LocalDate startDate, LocalDate expiringDate,
        CalendarData prevVersion, CalendarData nextVersion) {

    if ((startDate.compareTo(prevVersion.getExpiringDate()) <= 0) && (nextVersion.getExpiringDate() != null)
            && (expiringDate.compareTo(nextVersion.getExpiringDate()) >= 0)) {
        return true;
    }//from ww  w.  ja v  a 2 s .  com
    int indexPrevOfPrev = calendarDataVersions.indexOf(prevVersion);

    if (indexPrevOfPrev > 0) {
        CalendarData prevOfPrev = calendarDataVersions.get(indexPrevOfPrev - 1);
        if (startDate.compareTo(prevOfPrev.getExpiringDate()) <= 0) {
            return true;
        }
    }

    return false;
}

From source file:org.libreplan.business.calendars.entities.BaseCalendar.java

License:Open Source License

public CalendarData createLastVersion(LocalDate startDate) {
    CalendarData calendarData = getCalendarDataBeforeTheLastIfAny();
    if ((calendarData.getExpiringDate() != null)
            && (startDate.compareTo(calendarData.getExpiringDate()) <= 0)) {
        throw new IllegalArgumentException(
                "Wrong start date : the new work week includes a whole work week already exists");
    }/*w  w w  .  j  a  v  a 2s  .c  o m*/

    getLastCalendarData().setExpiringDate(startDate);

    CalendarData newCalendarData = CalendarData.create();
    calendarDataVersions.add(newCalendarData);
    Collections.sort(calendarDataVersions, CalendarData.BY_EXPIRING_DATE_COMPARATOR);

    return newCalendarData;
}

From source file:org.libreplan.business.calendars.entities.BaseCalendar.java

License:Open Source License

public CalendarData createFirstVersion(LocalDate expiringDate) {
    CalendarData firstVersion = getFirstCalendarData();
    if ((firstVersion.getExpiringDate() != null)
            && (expiringDate.compareTo(firstVersion.getExpiringDate()) >= 0)) {

        throw new IllegalArgumentException(
                "Wrong expiring date : Work week expiring date must be lower than expiring date for "
                        + "all work weeks of this calendar");
    }/*from  w ww  .  java 2 s  .  c om*/

    CalendarData newCalendarData = CalendarData.create();
    newCalendarData.setExpiringDate(expiringDate);
    calendarDataVersions.add(newCalendarData);
    Collections.sort(calendarDataVersions, CalendarData.BY_EXPIRING_DATE_COMPARATOR);

    return newCalendarData;
}