Example usage for org.joda.time LocalDate isEqual

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

Introduction

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

Prototype

public boolean isEqual(ReadablePartial partial) 

Source Link

Document

Is this partial the same as the specified partial.

Usage

From source file:com.axelor.apps.tool.date.DateTool.java

License:Open Source License

private static int days360Between(LocalDate startDate, LocalDate endDate) {

    int nbDayOfFirstMonth = 0;
    int nbDayOfOthersMonths = 0;
    int nbDayOfLastMonth = 0;

    LocalDate start = startDate;//from w  w  w.  j a  va 2s.c o  m

    if (endDate.getMonthOfYear() != startDate.getMonthOfYear() || endDate.getYear() != startDate.getYear()) {

        // First month :: if the startDate is not the last day of the month
        if (!startDate.isEqual(startDate.dayOfMonth().withMaximumValue())) {
            nbDayOfFirstMonth = 30 - startDate.getDayOfMonth();
        }

        // The startDate is included
        nbDayOfFirstMonth = nbDayOfFirstMonth + 1;

        // Months between the first one and the last one
        LocalDate date1 = startDate.plusMonths(1).dayOfMonth().withMinimumValue();
        while (endDate.getMonthOfYear() != date1.getMonthOfYear() || endDate.getYear() != date1.getYear()) {

            nbDayOfOthersMonths = nbDayOfOthersMonths + 30;
            date1 = date1.plusMonths(1);

        }

        // Last Month
        start = endDate.dayOfMonth().withMinimumValue();
    }

    if (endDate.isEqual(endDate.dayOfMonth().withMaximumValue())) {
        nbDayOfLastMonth = 30 - start.getDayOfMonth();
    } else {
        nbDayOfLastMonth = endDate.getDayOfMonth() - start.getDayOfMonth();
    }

    // The endDate is included
    nbDayOfLastMonth = nbDayOfLastMonth + 1;

    return nbDayOfFirstMonth + nbDayOfOthersMonths + nbDayOfLastMonth;
}

From source file:com.axelor.apps.tool.date.DateTool.java

License:Open Source License

public static boolean isProrata(LocalDate dateFrame1, LocalDate dateFrame2, LocalDate date1, LocalDate date2) {

    if (date2 == null && (date1.isBefore(dateFrame2) || date1.isEqual(dateFrame2))) {
        return true;
    } else if (date2 == null) {
        return false;
    }//from w  w  w .  j a va  2s  .  c  o  m

    if (((date1.isAfter(dateFrame1) || date1.isEqual(dateFrame1))
            && (date1.isBefore(dateFrame2) || date1.isEqual(dateFrame2)))
            || ((date2.isAfter(dateFrame1) || date2.isEqual(dateFrame1))
                    && (date2.isBefore(dateFrame2) || date2.isEqual(dateFrame2)))
            || (date1.isBefore(dateFrame1) && date2.isAfter(dateFrame2))) {

        return true;
    }

    return false;
}

From source file:com.axelor.apps.tool.date.DateTool.java

License:Open Source License

public static boolean isBetween(LocalDate dateFrame1, LocalDate dateFrame2, LocalDate date) {

    if (dateFrame2 == null && (date.isAfter(dateFrame1) || date.isEqual(dateFrame1))) {
        return true;
    } else if (dateFrame2 != null && (date.isAfter(dateFrame1) || date.isEqual(dateFrame1))
            && (date.isBefore(dateFrame2) || date.isEqual(dateFrame2))) {
        return true;
    } else {/* w w  w  .  ja v  a 2  s  .  c o m*/
        return false;
    }

}

From source file:com.esofthead.mycollab.core.utils.BusinessDayTimeUtils.java

License:Open Source License

public static int duration(LocalDate start, LocalDate end) {
    int candidateDuration = 1;
    if (start.isAfter(end)) {
        return -1;
    }//from w w w  .  j  av a2 s .com
    try {
        DateCalculator<LocalDate> calc1 = LocalDateKitCalculatorsFactory.forwardCalculator("MyCollab");
        calc1.setStartDate(start);
        start = calc1.getCurrentBusinessDate();
        calc1.setStartDate(end);
        if (calc1.isNonWorkingDay(end)) {
            candidateDuration -= 1;
            end = calc1.getCurrentBusinessDate();
        }
        long possibleDurations = (end.toDate().getTime() - start.toDate().getTime())
                / DateTimeUtils.MILLISECONDS_IN_A_DAY;
        int varDays = Math.round((possibleDurations + 1) / 2);
        calc1.setStartDate(start);
        LocalDate testDate;
        while (true) {
            LocalDate previousBizDate = calc1.getCurrentBusinessDate();
            calc1.moveByBusinessDays(varDays);
            testDate = calc1.getCurrentBusinessDate();
            if (testDate.isAfter(end)) {
                varDays = Math.round((varDays + 1) / 2);
                calc1.setCurrentBusinessDate(previousBizDate);
            } else if (testDate.isBefore(end)) {
                candidateDuration += varDays;
                varDays = Math.round(varDays / 2);
                calc1.setStartDate(testDate);
            } else {
                return candidateDuration + varDays;
            }

            if (varDays == 0) {
                calc1.setStartDate(testDate);
                calc1.moveByBusinessDays(1);
                testDate = calc1.getCurrentBusinessDate();
                if (!testDate.isEqual(end)) {
                    //                        LOG.error("Error while calculate duration of " + start + "--" + end);
                }
                return candidateDuration + 1;
            }
        }
    } catch (Exception e) {
        LOG.error("Error while calculate duration of " + start + "--" + end);
        return candidateDuration;
    }
}

From source file:com.gst.infrastructure.core.data.DataValidatorBuilder.java

License:Apache License

public DataValidatorBuilder validateDateForEqual(final LocalDate date) {
    if (this.value == null && this.ignoreNullValue) {
        return this;
    }//from w  w  w.  j  a  va2 s  .  com

    if (this.value != null && date != null) {
        final LocalDate dateVal = (LocalDate) this.value;
        if (!dateVal.isEqual(date)) {
            final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource)
                    .append(".").append(this.parameter).append(".is.not.equal.to.date");
            final StringBuilder defaultEnglishMessage = new StringBuilder("The ").append(this.parameter)
                    .append(" must be equal to provided date").append(date);
            final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(),
                    defaultEnglishMessage.toString(), this.parameter, dateVal, date);
            this.dataValidationErrors.add(error);
        }
    }
    return this;
}

From source file:com.gst.organisation.holiday.service.HolidayUtil.java

License:Apache License

public static boolean isHoliday(final LocalDate date, final List<Holiday> holidays) {
    for (final Holiday holiday : holidays) {
        if (date.isEqual(holiday.getFromDateLocalDate()) || date.isEqual(holiday.getToDateLocalDate())
                || (date.isAfter(holiday.getFromDateLocalDate())
                        && date.isBefore(holiday.getToDateLocalDate()))) {
            return true;
        }//from   w  ww  .j a v  a  2 s  .  c o m
    }

    return false;
}

From source file:com.gst.organisation.holiday.service.HolidayWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

private void validateInputDates(final LocalDate fromDate, final LocalDate toDate,
        final LocalDate repaymentsRescheduledTo) {

    String defaultUserMessage = "";

    if (toDate.isBefore(fromDate)) {
        defaultUserMessage = "To Date date cannot be before the From Date.";
        throw new HolidayDateException("to.date.cannot.be.before.from.date", defaultUserMessage,
                fromDate.toString(), toDate.toString());
    }// w  w  w .  ja  v  a  2s.c  o m

    if (repaymentsRescheduledTo.isEqual(fromDate) || repaymentsRescheduledTo.isEqual(toDate)
            || (repaymentsRescheduledTo.isAfter(fromDate) && repaymentsRescheduledTo.isBefore(toDate))) {

        defaultUserMessage = "Repayments rescheduled date should be before from date or after to date.";
        throw new HolidayDateException(
                "repayments.rescheduled.date.should.be.before.from.date.or.after.to.date", defaultUserMessage,
                repaymentsRescheduledTo.toString());
    }

    final WorkingDays workingDays = this.daysRepositoryWrapper.findOne();
    final Boolean isRepaymentOnWorkingDay = WorkingDaysUtil.isWorkingDay(workingDays, repaymentsRescheduledTo);

    if (!isRepaymentOnWorkingDay) {
        defaultUserMessage = "Repayments rescheduled date should not fall on non working days";
        throw new HolidayDateException("repayments.rescheduled.date.should.not.fall.on.non.working.day",
                defaultUserMessage, repaymentsRescheduledTo.toString());
    }

    // validate repaymentsRescheduledTo date
    // 1. should be within a 7 days date range.
    // 2. Alternative date should not be an exist holiday.//TBD
    // 3. Holiday should not be on an repaymentsRescheduledTo date of
    // another holiday.//TBD

    // restricting repaymentsRescheduledTo date to be within 7 days range
    // before or after from date and to date.
    if (repaymentsRescheduledTo.isBefore(fromDate.minusDays(7))
            || repaymentsRescheduledTo.isAfter(toDate.plusDays(7))) {
        defaultUserMessage = "Repayments Rescheduled to date must be within 7 days before or after from and to dates";
        throw new HolidayDateException("repayments.rescheduled.to.must.be.within.range", defaultUserMessage,
                fromDate.toString(), toDate.toString(), repaymentsRescheduledTo.toString());
    }
}

From source file:com.gst.portfolio.floatingrates.data.FloatingRateDTO.java

License:Apache License

public BigDecimal fetchBaseRate(LocalDate date) {
    BigDecimal rate = null;//from  w w w  .  j  a v  a 2  s. c o m
    for (FloatingRatePeriodData periodData : this.baseLendingRatePeriods) {
        final LocalDate periodFromDate = new LocalDate(periodData.getFromDate());
        if (periodFromDate.isBefore(date) || periodFromDate.isEqual(date)) {
            rate = periodData.getInterestRate();
            break;
        }
    }
    return rate;
}

From source file:com.gst.portfolio.loanaccount.data.LoanTermVariationsDataWrapper.java

License:Apache License

public LoanTermVariationsData fetchLoanTermDueDateVariationsData(final LocalDate onDate) {
    LoanTermVariationsData data = null;//  w  w  w.j  a  v a2 s.c om
    for (LoanTermVariationsData termVariationsData : this.dueDateVariation) {
        if (onDate.isEqual(termVariationsData.getTermApplicableFrom())) {
            data = termVariationsData;
            break;
        }
    }
    return data;
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

private boolean isChronologicallyLatestRepaymentOrWaiver(final LoanTransaction loanTransaction,
        final List<LoanTransaction> loanTransactions) {

    boolean isChronologicallyLatestRepaymentOrWaiver = true;

    final LocalDate currentTransactionDate = loanTransaction.getTransactionDate();
    for (final LoanTransaction previousTransaction : loanTransactions) {
        if (!previousTransaction.isDisbursement() && previousTransaction.isNotReversed()) {
            if (currentTransactionDate.isBefore(previousTransaction.getTransactionDate())
                    || currentTransactionDate.isEqual(previousTransaction.getTransactionDate())) {
                isChronologicallyLatestRepaymentOrWaiver = false;
                break;
            }/*from  w  ww . j ava 2 s.com*/
        }
    }

    return isChronologicallyLatestRepaymentOrWaiver;
}