Example usage for org.joda.time LocalDate isBefore

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

Introduction

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

Prototype

public boolean isBefore(ReadablePartial partial) 

Source Link

Document

Is this partial earlier than the specified partial.

Usage

From source file:com.github.serddmitry.jodainterval.LocalDateIntervalWithLowerBound.java

License:Apache License

@Override
public boolean contains(LocalDate date) {
    return !date.isBefore(first);
}

From source file:com.google.api.ads.adwords.awreporting.model.entities.DateRangeAndType.java

License:Open Source License

/**
 * Make constructor private so it can only be created by factory method.
 *//* w ww  . j  a  v  a  2  s  .  c o m*/
private DateRangeAndType(LocalDate startDate, LocalDate endDate, ReportDefinitionDateRangeType type) {
    this.startDate = Preconditions.checkNotNull(startDate, "Argument 'startDate' cannot be null.");
    this.endDate = Preconditions.checkNotNull(endDate, "Argument 'endDate' cannot be null.");
    this.type = Preconditions.checkNotNull(type, "Argument 'type' cannot be null.");

    Preconditions.checkArgument(!endDate.isBefore(startDate),
            "Start date must be before or equal to end date.");
}

From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);
    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }//from   w ww . j a va2s.  c  om
    LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate();
    smsCampaign.setLastTriggerDate(nextTriggerDate.toDate());
    // calculate new trigger date and insert into next trigger date

    /**
     * next run time has to be in the future if not calculate a new future
     * date
     */
    LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
            smsCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
    if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means
                                                                  // next
                                                                  // run
                                                                  // time is
                                                                  // in the
                                                                  // past
                                                                  // calculate
                                                                  // a new
                                                                  // future
                                                                  // date
        nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                smsCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();
    final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":"
            + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
    final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

    smsCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.smsCampaignRepository.saveAndFlush(smsCampaign);
}

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

License:Apache License

public DataValidatorBuilder validateDateBefore(final LocalDate date) {
    if (this.value == null && this.ignoreNullValue) {
        return this;
    }//  ww w .ja  v  a 2  s  .co  m

    if (this.value != null && date != null) {
        final LocalDate dateVal = (LocalDate) this.value;
        if (date.isBefore(dateVal)) {
            final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource)
                    .append(".").append(this.parameter).append(".is.greater.than.date");
            final StringBuilder defaultEnglishMessage = new StringBuilder("The ").append(this.parameter)
                    .append(" must be less than 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.infrastructure.core.domain.LocalDateInterval.java

License:Apache License

private boolean isBetweenInclusive(final LocalDate start, final LocalDate end, final LocalDate target) {
    return !target.isBefore(start) && !target.isAfter(end);
}

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

License:Apache License

public static LocalDate getRepaymentRescheduleDateToIfHoliday(LocalDate repaymentDate,
        final List<Holiday> holidays) {

    for (final Holiday holiday : holidays) {
        if (repaymentDate.equals(holiday.getFromDateLocalDate())
                || repaymentDate.equals(holiday.getToDateLocalDate())
                || (repaymentDate.isAfter(holiday.getFromDateLocalDate())
                        && repaymentDate.isBefore(holiday.getToDateLocalDate()))) {
            repaymentDate = getRepaymentRescheduleDateIfHoliday(repaymentDate, holidays);
        }//from  w  ww . j a v  a  2s. c  om
    }
    return repaymentDate;
}

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

License:Apache License

private static LocalDate getRepaymentRescheduleDateIfHoliday(final LocalDate repaymentDate,
        final List<Holiday> holidays) {

    for (final Holiday holiday : holidays) {
        if (repaymentDate.equals(holiday.getFromDateLocalDate())
                || repaymentDate.equals(holiday.getToDateLocalDate())
                || (repaymentDate.isAfter(holiday.getFromDateLocalDate())
                        && repaymentDate.isBefore(holiday.getToDateLocalDate()))) {
            // should be take from holiday
            return holiday.getRepaymentsRescheduledToLocalDate();
        }//from  w ww . j  av a 2 s.  co  m
    }
    return repaymentDate;
}

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 ww w.j  av a 2 s .  com*/
    }

    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());
    }//from w  w  w  .java2  s  .  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.organisation.teller.serialization.TellerCommandFromApiJsonDeserializer.java

License:Apache License

public void validateForCreateAndUpdateTeller(final String json) {
    if (StringUtils.isBlank(json)) {
        throw new InvalidJsonException();
    }//from  ww  w.j  ava2s. c  om

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("teller");

    final JsonElement element = this.fromApiJsonHelper.parse(json);

    final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element);
    baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();

    final String name = this.fromApiJsonHelper.extractStringNamed("name", element);
    baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(50);

    final String description = this.fromApiJsonHelper.extractStringNamed("description", element);
    baseDataValidator.reset().parameter("description").value(description).notExceedingLengthOf(100);

    final LocalDate startDate = this.fromApiJsonHelper.extractLocalDateNamed("startDate", element);
    baseDataValidator.reset().parameter("startDate").value(startDate).notNull();

    final LocalDate endDate = this.fromApiJsonHelper.extractLocalDateNamed("endDate", element);
    baseDataValidator.reset().parameter("endDate").value(endDate).ignoreIfNull();

    final String status = this.fromApiJsonHelper.extractStringNamed("status", element);
    baseDataValidator.reset().parameter("status").value(status).notBlank().notExceedingLengthOf(50);

    if (endDate != null) {
        if (endDate.isBefore(startDate)) {
            throw new InvalidDateInputException(startDate.toString(), endDate.toString());
        }
    }
    throwExceptionIfValidationWarningsExist(dataValidationErrors);
}