Example usage for org.joda.time LocalDate isAfter

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

Introduction

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

Prototype

public boolean isAfter(ReadablePartial partial) 

Source Link

Document

Is this partial later than the specified partial.

Usage

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;
    }//w ww.ja v  a 2s.c o  m
    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.esofthead.mycollab.module.project.view.assignments.gantt.GanttItemWrapper.java

License:Open Source License

public boolean setStartAndEndDate(LocalDate newStartDate, LocalDate newEndDate, boolean askToCheckPredecessors,
        boolean requestToCheckDependents) {
    if (newStartDate.isBefore(fixedStartDateByChilds) || newEndDate.isAfter(fixedEndDatebyChilds)) {
        throw new UserInvalidInputException("Invalid constraints");
    }//from w w w .j  av a 2 s .c  o  m
    boolean hasChange = false;
    if (!this.startDate.isEqual(newStartDate)) {
        hasChange = true;
        this.startDate = newStartDate;
        task.setStartDate(startDate.toDate());
        ownStep.setStartDate(startDate.toDate());
    }

    if (!this.endDate.isEqual(newEndDate)) {
        hasChange = true;
        this.endDate = newEndDate;
        task.setEndDate(endDate.toDate());
        ownStep.setEndDate(endDate.plusDays(1).toDate());
    }

    if (hasChange) {
        int duration = BusinessDayTimeUtils.duration(newStartDate, newEndDate);
        setDuration(duration * DateTimeUtils.MILISECONDS_IN_A_DAY);
        onDateChanges(askToCheckPredecessors, requestToCheckDependents);
    }

    return hasChange;
}

From source file:com.esofthead.mycollab.module.project.view.assignments.gantt.GanttItemWrapper.java

License:Open Source License

public void adjustTaskDatesByPredecessors(List<TaskPredecessor> predecessors) {
    if (CollectionUtils.isNotEmpty(predecessors)) {
        LocalDate currentStartDate = new LocalDate(getStartDate());
        LocalDate currentEndDate = new LocalDate(getEndDate());
        LocalDate boundStartDate = new LocalDate(1970, 1, 1);
        LocalDate boundEndDate = new LocalDate(2100, 1, 1);

        for (TaskPredecessor predecessor : predecessors) {
            int ganttIndex = predecessor.getGanttIndex();

            GanttItemWrapper ganttPredecessor = gantt.getBeanContainer().getItemByGanttIndex(ganttIndex);
            int dur = getDuration().intValue() - 1;
            if (ganttPredecessor != null) {
                Integer lagDay = predecessor.getLagday() + 1;

                if (TaskPredecessor.FS.equals(predecessor.getPredestype())) {
                    LocalDate endDate = new LocalDate(ganttPredecessor.getEndDate());
                    endDate = endDate.plusDays(1);
                    LocalDate expectedStartDate = BusinessDayTimeUtils.plusDays(endDate, lagDay);
                    if (boundStartDate.isBefore(expectedStartDate)) {
                        boundStartDate = expectedStartDate;
                    }/*from w ww.j a v  a2s  .  c  om*/
                    if (currentStartDate.isBefore(expectedStartDate)) {
                        currentStartDate = expectedStartDate;
                        LocalDate expectedEndDate = currentStartDate.plusDays(dur);
                        currentEndDate = DateTimeUtils.min(boundEndDate, expectedEndDate);
                    }
                } else if (TaskPredecessor.FF.equals(predecessor.getPredestype())) {
                    LocalDate endDate = new LocalDate(ganttPredecessor.getEndDate());
                    LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(endDate, lagDay);
                    if (boundEndDate.isAfter(expectedEndDate)) {
                        boundEndDate = expectedEndDate;
                    }
                    if (currentEndDate.isAfter(expectedEndDate)) {
                        currentEndDate = expectedEndDate;
                        LocalDate expectedStartDate = currentEndDate.minusDays(dur);
                        currentStartDate = DateTimeUtils.max(boundStartDate, expectedStartDate);
                    }
                } else if (TaskPredecessor.SF.equals(predecessor.getPredestype())) {
                    LocalDate startDate = new LocalDate(ganttPredecessor.getStartDate());
                    LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(startDate, lagDay);
                    if (boundEndDate.isAfter(expectedEndDate)) {
                        boundEndDate = expectedEndDate;
                    }
                    if (currentEndDate.isAfter(expectedEndDate)) {
                        currentEndDate = expectedEndDate;
                        LocalDate expectedStartDate = currentEndDate.minusDays(dur);
                        currentStartDate = DateTimeUtils.max(boundStartDate, expectedStartDate);
                    }
                } else if (TaskPredecessor.SS.equals(predecessor.getPredestype())) {
                    LocalDate startDate = new LocalDate(ganttPredecessor.getStartDate());
                    LocalDate expectedStartDate = BusinessDayTimeUtils.plusDays(startDate, lagDay);

                    if (boundStartDate.isBefore(expectedStartDate)) {
                        boundStartDate = expectedStartDate;
                    }

                    if (currentStartDate.isBefore(expectedStartDate)) {
                        currentStartDate = expectedStartDate;
                        LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(startDate, dur);
                        currentEndDate = DateTimeUtils.min(boundEndDate, expectedEndDate);
                    }
                } else {
                    throw new MyCollabException(
                            "Do not support predecessor type " + predecessor.getPredestype());
                }

                if (currentEndDate.isBefore(currentStartDate)) {
                    throw new UserInvalidInputException("Invalid constraint");
                }
            }
        }

        setStartAndEndDate(currentStartDate, currentEndDate, false, true);
    }
}

From source file:com.github.fauu.natrank.model.entity.Period.java

License:Open Source License

public boolean includesDate(LocalDate date) {
    return (!date.isBefore(fromDate) && (toDate == null || !date.isAfter(toDate)));
}

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

License:Apache License

LocalDateIntervalImpl(LocalDate first, LocalDate last) {
    this.first = checkNotNull(first, "lower bound of the interval cannot be null");
    this.last = checkNotNull(last, "upper bound of the interval cannot be null");
    checkArgument(!first.isAfter(last), "lower bound %s cannot be after upper bound %s", first, last);
    this.days = Days.daysBetween(first, last).getDays() + 1; // interval includes 'last' date, therefore, adding 1
}

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

License:Apache License

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

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

License:Apache License

@Override
public boolean contains(LocalDate date) {
    return !date.isAfter(last);
}

From source file:com.gst.infrastructure.campaigns.sms.domain.SmsCampaign.java

License:Apache License

private boolean isDateInTheFuture(final LocalDate localDate) {
    return localDate.isAfter(DateUtils.getLocalDateOfTenant());
}

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

License:Apache License

public DataValidatorBuilder validateDateAfter(final LocalDate date) {
    if (this.value == null && this.ignoreNullValue) {
        return this;
    }//from   ww  w . j a va 2s . c om

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

License:Apache License

public DataValidatorBuilder validateDateBeforeOrEqual(final LocalDate date) {
    if (this.value == null && this.ignoreNullValue) {
        return this;
    }/*from ww  w .j  a  v a2s .  c  o  m*/

    if (this.value != null && date != null) {
        final LocalDate dateVal = (LocalDate) this.value;
        if (dateVal.isAfter(date)) {
            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 or 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;
}