Example usage for org.joda.time DateTime plusDays

List of usage examples for org.joda.time DateTime plusDays

Introduction

In this page you can find the example usage for org.joda.time DateTime plusDays.

Prototype

public DateTime plusDays(int days) 

Source Link

Document

Returns a copy of this datetime plus the specified number of days.

Usage

From source file:org.mifos.calendar.WorkingDay.java

License:Open Source License

public static DateTime nearestWorkingDayOnOrAfter(final DateTime day, final List<Days> workingDays) {

    if (workingDays == null || workingDays.isEmpty()) {
        throw new IllegalStateException("workingDays cannot be null or empty");
    }//from   w w  w.j  av  a  2  s.c o m

    DateTime nextWorkingDay = day;
    while (isNotWorkingDay(nextWorkingDay, workingDays)) {
        nextWorkingDay = nextWorkingDay.plusDays(1);
    }
    return nextWorkingDay;
}

From source file:org.mifos.customers.struts.action.CustSearchAction.java

License:Open Source License

/**
 * Retrieve meetings for loan officer for selected day.
 * @param personnel/*from  w w  w  .  j a va 2  s .  c  om*/
 * @param request
 * @return
 * @throws Exception
 */
private String loadLoanOfficerCustomersHierarchyForSelectedDay(Short userId, HttpServletRequest request,
        CustSearchActionForm form) throws Exception {
    CustomerHierarchyDto hierarchy;
    List<String> nearestDates = new ArrayList<String>();
    DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
    Date selectedDate;

    DateTime nextDate = new DateTime();
    for (int i = 0; i < 7; i++) {
        nearestDates.add(formatter.format(nextDate.toDate()));
        nextDate = nextDate.plusDays(1);
    }

    if (form.getSelectedDateOption() != null) {
        selectedDate = formatter.parse(form.getSelectedDateOption());
    } else {
        selectedDate = new LocalDate().toDateMidnight().toDate();
    }

    hierarchy = personnelServiceFacade.getLoanOfficerCustomersHierarchyForDay(userId,
            new DateTime(selectedDate));

    SessionUtils.setCollectionAttribute("nearestDates", nearestDates, request);
    SessionUtils.setAttribute("hierarchy", hierarchy, request);
    return CustomerSearchConstants.LOADFORWARDLOANOFFICER_SUCCESS;
}

From source file:org.mifos.dmt.business.Meetings.schedule.Schedule.java

License:Open Source License

protected DateTime getWorkingDay(DateTime meetingDate) {
    int iDoW;/*from   w w  w .  j av  a 2 s  . co m*/
    iDoW = meetingDate.dayOfWeek().get();
    while (iDoW == 7) {
        meetingDate = meetingDate.plusDays(1);
        iDoW = meetingDate.dayOfWeek().get();
    }
    return meetingDate;
}

From source file:org.mifos.schedule.internal.DailyScheduledEvent.java

License:Open Source License

@Override
public DateTime rollFrowardDateByFrequency(DateTime date) {
    return date.plusDays(this.every);
}

From source file:org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration.java

License:Open Source License

@Override
public List<DateTime> generateScheduledDatesThrough(DateTime lastScheduledDate, DateTime throughDate,
        ScheduledEvent scheduledEvent, boolean isCustomerSchedule) {

    DateTime lastGeneratedDate = lastScheduledDate;
    List<DateTime> generatedDates = new ArrayList<DateTime>();
    do {/*from   w  ww . j  a  va  2s.c om*/
        generatedDates
                .addAll(this.generateScheduledDates(10, lastGeneratedDate, scheduledEvent, isCustomerSchedule));
        lastGeneratedDate = generatedDates.get(generatedDates.size() - 1);

        if (lastGeneratedDate.isBefore(throughDate)) {
            // roll forward date by one
            lastGeneratedDate = lastGeneratedDate.plusDays(1);
        }

    } while (lastGeneratedDate.isBefore(throughDate));

    return removeDatesAfterThroughDate(generatedDates, throughDate);
}

From source file:org.mifos.schedule.internal.HolidayAndWorkingDaysScheduledDateGeneration.java

License:Open Source License

/**
 * @param lastScheduledDate starting point for schedule generation
 *//*from  w ww.j  a va  2 s  .  co m*/
@Override
public List<DateTime> generateScheduledDates(final int occurences, final DateTime lastScheduledDate,
        final ScheduledEvent scheduledEvent, boolean isCustomerSchedule) {

    DateTime matchingDayOfWeekDate = lastScheduledDate;
    boolean isDailyMeeting = scheduledEvent instanceof DailyScheduledEvent;

    if (!isDailyMeeting) {
        matchingDayOfWeekDate = scheduledEvent.nearestMatchingDateBeginningAt(lastScheduledDate);
        if (isCustomerSchedule) {
            matchingDayOfWeekDate = scheduledEvent
                    .nearestMatchNotTakingIntoAccountScheduleFrequency(lastScheduledDate);
        }
    }

    List<DateTime> scheduledDates = new ArrayList<DateTime>();

    // Prepare a list of dates scheduled without adjusting working days/holidays.
    // It is used for computing next dates by 'ScheduledEvent' to omit problems
    // when adjusting a date changes a month (MIFOS-3584).
    List<DateTime> scheduledWithoutAdjustments = new ArrayList<DateTime>();
    DateTime withoutAdjustment = new DateTime(matchingDayOfWeekDate);
    scheduledWithoutAdjustments.add(withoutAdjustment);
    for (int i = 0; i < occurences; i++) {
        withoutAdjustment = scheduledEvent.nextEventDateAfter(withoutAdjustment);
        scheduledWithoutAdjustments.add(withoutAdjustment);
    }

    HashSet<DateTime> generatedDates = new HashSet<DateTime>();
    DateTime latestGeneratedDate = scheduledWithoutAdjustments.get(0);
    for (int i = 0; i < occurences; i++) {

        DateAdjustmentStrategy workingDay = new BasicWorkingDayStrategy(workingDays);
        DateTime adjustedForWorkingDay = workingDay.adjust(latestGeneratedDate);

        while (isDailyMeeting && generatedDates.contains(adjustedForWorkingDay)) {
            adjustedForWorkingDay = workingDay.adjust(adjustedForWorkingDay.plusDays(1));
        }

        DateAdjustmentStrategy holidayAdjustment = new BasicHolidayStrategy(upcomingHolidays, workingDays,
                scheduledEvent);
        DateTime adjustedForHolidays = holidayAdjustment.adjust(adjustedForWorkingDay);

        generatedDates.add(adjustedForHolidays);
        scheduledDates.add(adjustedForHolidays);
        latestGeneratedDate = scheduledEvent.nextEventDateAfter(scheduledWithoutAdjustments.get(i));
    }

    return scheduledDates;
}

From source file:org.mifos.test.acceptance.framework.loan.CreateLoanAccountReviewInstallmentPage.java

License:Open Source License

private void validateInvalidDateFormat(int noOfInstallments, DateTime disbursalDate, String dateFormat,
        int minGap) {
    DateTime nextInstallment = disbursalDate;
    for (int installment = 0; installment < noOfInstallments; installment++) {
        nextInstallment = nextInstallment.plusDays(minGap);
        setInstallmentDate(String.valueOf(installment),
                DateTimeFormat.forPattern(dateFormat).print(nextInstallment));
    }/* w  ww  .j  a v  a 2s .c  om*/
    clickValidateAndWaitForPageToLoad();
    for (int installment = 0; installment < noOfInstallments; installment++) {
        // Assert.Assert.assertTrue(selenium.isTextPresent("Installment " + (installment+1) +" has an invalid due date. An example due date is 23-Apr-2010"));
    }
}

From source file:org.mifos.test.acceptance.framework.loan.CreateLoanAccountReviewInstallmentPage.java

License:Open Source License

private DateTime getValidDate(DateTime disbursalDate, int minGap, boolean isGapIsMinimumGap) {
    DateTime dateTime = disbursalDate.plusDays(minGap);
    if (dateTime.getDayOfWeek() == 7) {
        if (isGapIsMinimumGap) {
            dateTime = dateTime.plusDays(1);
        } else {/*from  ww  w  .  j a v a2  s .  co  m*/
            dateTime = dateTime.minusDays(1);
        }
    }
    return dateTime;
}

From source file:org.mifos.test.acceptance.framework.loan.RedoLoanDisbursalSchedulePreviewPage.java

License:Open Source License

private void validateInvalidDateFormat(int noOfInstallments, DateTime disbursalDate, String dateFormat,
        int minGap) {
    DateTime nextInstallment = disbursalDate;
    for (int installment = 0; installment < noOfInstallments; installment++) {
        nextInstallment = nextInstallment.plusDays(minGap);
        setInstallmentDate(String.valueOf(installment),
                DateTimeFormat.forPattern(dateFormat).print(nextInstallment));
    }// w  w  w .  j  a  v  a  2  s .c om
    clickPreviewButtonAndWaitForPageToLoad();
    for (int installment = 0; installment < noOfInstallments; installment++) {
        // Assert.assertTrue(selenium.isTextPresent("Installment " + (installment+1) +" has an invalid due date. An example due date is 23-Apr-2010"));
    }
}

From source file:org.mifos.test.acceptance.framework.loan.RedoLoanDisbursalSchedulePreviewPage.java

License:Open Source License

private DateTime getValidDate(DateTime date, int minimumGap, boolean isGapIsMinimumGap) {
    DateTime dateTime = date.plusDays(minimumGap);
    if (dateTime.getDayOfWeek() == 7) {
        if (isGapIsMinimumGap) {
            dateTime = dateTime.plusDays(1);
        } else {/*from w ww  . j a v a  2s.  c  o  m*/
            dateTime = dateTime.minusDays(1);
        }
    }
    return dateTime;
}