Example usage for org.joda.time LocalDate minusDays

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

Introduction

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

Prototype

public LocalDate minusDays(int days) 

Source Link

Document

Returns a copy of this date minus the specified number of days.

Usage

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  w w.j a  v  a  2 s .c  o  m*/
                    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.example.weatherforecast.utils.DateUtils.java

License:Open Source License

public static long toEpochMillisPreviousDay(LocalDate date) {
    return date.minusDays(1).toDateTimeAtStartOfDay().getMillis();
}

From source file:com.excilys.sugadroid.tasks.GetInitialCalendarTask.java

License:Open Source License

@Override
public void doRunAuthenticatedTask() throws ServiceException {

    Map<LocalDate, List<IAppointmentBean>> initialDaysAppointments;

    LocalDate today = new LocalDate();
    LocalDate before = today.minusDays(appointmentsLoadingBefore);
    LocalDate after = today.plusDays(appointmentsLoadingAfter);

    initialDaysAppointments = appointmentServices.getAppointmentsInInterval(before, after);

    EagerLoadingCalendar calendar = new EagerLoadingCalendar(before, after, initialDaysAppointments);

    activity.onInitialCalendarLoaded(calendar);

}

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

License:Apache License

/** An interval [from .. to) - equivalent to [from .. to-1] */
public static LocalDateInterval excludingLast(LocalDate from, LocalDate to) {
    checkNotNull(to, "upper bound of the interval cannot be null");
    return new LocalDateIntervalImpl(from, to.minusDays(1));
}

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

License:Apache License

/** An interval (- .. to) - equivalent to (- .. to-1] */
public static LocalDateIntervalPartial upToAndExcluding(LocalDate to) {
    checkNotNull(to, "upper bound of the interval cannot be null");
    return new LocalDateIntervalWithUpperBound(to.minusDays(1));
}

From source file:com.google.api.ads.adwords.awalerting.util.DateRange.java

License:Open Source License

/**
 * Parse DateRange in ReportDefinitionDateRangeType enum format.
 *//*from www.  ja v  a2s. c  o  m*/
private static DateRange parseEnumFormat(String dateRange) {
    ReportDefinitionDateRangeType dateRangeType;
    try {
        dateRangeType = ReportDefinitionDateRangeType.valueOf(dateRange);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Unknown DateRange type: " + dateRange);
    }

    LocalDate today = LocalDate.now();
    LocalDate startDate;
    LocalDate endDate;
    switch (dateRangeType) {
    case TODAY:
        startDate = endDate = today;
        break;
    case YESTERDAY:
        startDate = endDate = today.minusDays(1);
        break;
    case LAST_7_DAYS:
        startDate = today.minusDays(7);
        endDate = today.minusDays(1);
        break;
    case LAST_WEEK:
        LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek();
        startDate = lastWeekProp.withMinimumValue();
        endDate = lastWeekProp.withMaximumValue();
        break;
    case THIS_MONTH:
        LocalDate.Property thisMonthProp = today.dayOfMonth();
        startDate = thisMonthProp.withMinimumValue();
        endDate = thisMonthProp.withMaximumValue();
        break;
    case LAST_MONTH:
        LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth();
        startDate = lastMonthProp.withMinimumValue();
        endDate = lastMonthProp.withMaximumValue();
        break;
    case LAST_14_DAYS:
        startDate = today.minusDays(14);
        endDate = today.minusDays(1);
        break;
    case LAST_30_DAYS:
        startDate = today.minusDays(30);
        endDate = today.minusDays(1);
        break;
    case THIS_WEEK_SUN_TODAY:
        // Joda-Time uses the ISO standard Monday to Sunday week.
        startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue();
        endDate = today;
        break;
    case THIS_WEEK_MON_TODAY:
        startDate = today.dayOfWeek().withMinimumValue();
        endDate = today;
        break;
    case LAST_WEEK_SUN_SAT:
        startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue();
        endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1);
        break;
    // Don't support the following enums
    case LAST_BUSINESS_WEEK:
    case ALL_TIME:
    case CUSTOM_DATE:
    default:
        throw new IllegalArgumentException("Unsupported DateRange type: " + dateRange);
    }

    return new DateRange(startDate, endDate);
}

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

License:Open Source License

/**
 * Parse DateRange in ReportDefinitionDateRangeType enum format.
 *///from  w  w w .j a v a2  s  .  c om
private static DateRangeAndType parseEnumFormat(ReportDefinitionDateRangeType type) {
    LocalDate today = LocalDate.now();
    LocalDate startDate;
    LocalDate endDate;
    switch (type) {
    case TODAY:
        startDate = endDate = today;
        break;
    case YESTERDAY:
        startDate = endDate = today.minusDays(1);
        break;
    case LAST_7_DAYS:
        startDate = today.minusDays(7);
        endDate = today.minusDays(1);
        break;
    case LAST_WEEK:
        LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek();
        startDate = lastWeekProp.withMinimumValue();
        endDate = lastWeekProp.withMaximumValue();
        break;
    case THIS_MONTH:
        LocalDate.Property thisMonthProp = today.dayOfMonth();
        startDate = thisMonthProp.withMinimumValue();
        endDate = thisMonthProp.withMaximumValue();
        break;
    case LAST_MONTH:
        LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth();
        startDate = lastMonthProp.withMinimumValue();
        endDate = lastMonthProp.withMaximumValue();
        break;
    case LAST_14_DAYS:
        startDate = today.minusDays(14);
        endDate = today.minusDays(1);
        break;
    case LAST_30_DAYS:
        startDate = today.minusDays(30);
        endDate = today.minusDays(1);
        break;
    case THIS_WEEK_SUN_TODAY:
        // Joda-Time uses the ISO standard Monday to Sunday week.
        startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue();
        endDate = today;
        break;
    case THIS_WEEK_MON_TODAY:
        startDate = today.dayOfWeek().withMinimumValue();
        endDate = today;
        break;
    case LAST_WEEK_SUN_SAT:
        startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue();
        endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1);
        break;
    // Don't support the following enums
    case LAST_BUSINESS_WEEK:
    case ALL_TIME:
    case CUSTOM_DATE:
    default:
        throw new IllegalArgumentException("Unsupported DateRange type: " + type.value());
    }

    return new DateRangeAndType(startDate, endDate, type);
}

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());
    }//  ww w  .  j a va 2 s .  com

    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.workingdays.service.WorkingDaysUtil.java

License:Apache License

public static LocalDate getOffSetDateIfNonWorkingDay(final LocalDate date, final LocalDate nextMeetingDate,
        final WorkingDays workingDays) {

    // If date is not a non working day then return date.
    if (isWorkingDay(workingDays, date)) {
        return date;
    }//from w w w . j a  va2s  . c o  m

    final RepaymentRescheduleType rescheduleType = RepaymentRescheduleType
            .fromInt(workingDays.getRepaymentReschedulingType());

    switch (rescheduleType) {
    case INVALID:
        return date;
    case SAME_DAY:
        return date;
    case MOVE_TO_NEXT_WORKING_DAY:
        return getOffSetDateIfNonWorkingDay(date.plusDays(1), nextMeetingDate, workingDays);
    case MOVE_TO_NEXT_REPAYMENT_MEETING_DAY:
        return nextMeetingDate;
    case MOVE_TO_PREVIOUS_WORKING_DAY:
        return getOffSetDateIfNonWorkingDay(date.minusDays(1), nextMeetingDate, workingDays);
    default:
        return date;
    }
}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static boolean isValidRecurringDate(final Recur recur, final LocalDate seedDate, final LocalDate date,
        boolean isSkipRepaymentonFirstDayOfMonth, final int numberOfDays) {
    LocalDate startDate = date;
    if (isSkipRepaymentonFirstDayOfMonth && date.getDayOfMonth() == (numberOfDays + 1)) {
        startDate = startDate.minusDays(numberOfDays);
    }//from  ww w . j  a v a  2  s.  c  o  m
    final Collection<LocalDate> recurDate = getRecurringDates(recur, seedDate, startDate, date.plusDays(1), 1,
            isSkipRepaymentonFirstDayOfMonth, numberOfDays);

    return (recurDate == null || recurDate.isEmpty()) ? false : recurDate.contains(date);
}