Example usage for org.joda.time LocalDate plus

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

Introduction

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

Prototype

public LocalDate plus(ReadablePeriod period) 

Source Link

Document

Returns a copy of this date with the specified period added.

Usage

From source file:org.angnysa.yaba.service.impl.DefaultTransactionService.java

License:Open Source License

@Override
public List<SimulationDetail> simulate(double initial, LocalDate start, LocalDate end, ReadablePeriod period) {

    List<SimulationDetail> result = new ArrayList<SimulationDetail>();

    trs_loop: for (TransactionDefinition td : getAll()) {
        // current insertion point (CIP)
        int cip = 0;
        // the amount added/removed by the current actual transaction (AT)
        double delta = 0D;

        // init/*w w w .j  a v a 2s  . c  om*/
        if (cip >= result.size()) {
            SimulationDetail detail = new SimulationDetail();
            detail.setDate(start);
            detail.setRemainingAmount(initial);
            result.add(detail);
        }

        for (Transaction t : computeTransactions(td, start, end)) {

            // if the AT occurs after the CIP,
            // update all CIP until we find the next valid CIP
            while (t.getDate().isAfter(result.get(cip).getDate())) {

                result.get(cip).setRemainingAmount(result.get(cip).getRemainingAmount() + delta);

                cip++;

                // init
                if (cip >= result.size()) {

                    LocalDate date = result.get(cip - 1).getDate().plus(period);
                    // if the end date doesn't end a full period, we can have some transactions that cannot be properly used.
                    // we stop here if it's the case.
                    if (date.isAfter(end)) {
                        continue trs_loop;
                    }

                    SimulationDetail detail = new SimulationDetail();
                    detail.setDate(date);
                    detail.setRemainingAmount(initial);
                    result.add(detail);
                }
            }

            // store the AT in its CIP
            result.get(cip).getTransactions().add(t);

            // update the delta
            delta += t.getAmount();
        }

        // update all remaining points
        LocalDate date = result.get(cip).getDate();
        while (!date.isAfter(end)) {

            //init
            if (cip >= result.size()) {
                SimulationDetail detail = new SimulationDetail();
                detail.setDate(date);
                detail.setRemainingAmount(initial);
                result.add(detail);
            }

            result.get(cip).setRemainingAmount(result.get(cip).getRemainingAmount() + delta);

            date = date.plus(period);
            cip++;
        }
    }

    return result;
}

From source file:org.estatio.dom.lease.breaks.RollingBreakOption.java

License:Apache License

@Override
public LocalDate getCurrentBreakDate() {
    final LocalDate notificationDate = laterOf(getExerciseDate(), getClockService().now());
    return notificationDate.plus(getNotificationPeriodJoda());
}

From source file:org.estatio.dom.lease.Leases.java

License:Apache License

private static LocalDate calculateEndDate(final LocalDate startDate, final LocalDate endDate,
        final String duration) {
    if (duration != null) {
        final Period p = JodaPeriodUtils.asPeriod(duration);
        if (p != null) {
            return startDate.plus(p).minusDays(1);
        }//from   w ww .  j a v a 2s . co m
    }
    return endDate;
}

From source file:org.isisaddons.module.fakedata.dom.JodaLocalDates.java

License:Apache License

@Programmatic
public LocalDate after(final Period period) {
    final LocalDate now = fake.clockService.now();
    return now.plus(period);
}

From source file:org.killbill.billing.invoice.proRations.inAdvance.GenericProRationTestBase.java

License:Apache License

@Test(groups = "fast")
public void testSinglePlan_OnePeriodLessADayAfterStart() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 15);
    final LocalDate targetDate = startDate.plus(getBillingPeriod().getPeriod()).plusDays(-1);

    testCalculateNumberOfBillingCycles(startDate, targetDate, 15, ONE);
}

From source file:org.killbill.billing.invoice.proRations.inAdvance.GenericProRationTestBase.java

License:Apache License

@Test(groups = "fast")
public void testSinglePlan_ExactlyOnePeriodAfterStart() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 15);
    final LocalDate targetDate = startDate.plus(getBillingPeriod().getPeriod());

    testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}

From source file:org.killbill.billing.invoice.proRations.inAdvance.GenericProRationTestBase.java

License:Apache License

@Test(groups = "fast")
public void testSinglePlan_SlightlyMoreThanOnePeriodAfterStart() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 15);
    final LocalDate targetDate = startDate.plus(getBillingPeriod().getPeriod()).plusDays(1);

    testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}

From source file:org.killbill.billing.invoice.proRations.inAdvance.GenericProRationTestBase.java

License:Apache License

@Test(groups = "fast")
public void testSinglePlan_CrossingYearBoundary() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 12, 15);
    final LocalDate oneCycleLater = startDate.plus(getBillingPeriod().getPeriod());

    // test just before the billing cycle day
    testCalculateNumberOfBillingCycles(startDate, oneCycleLater.plusDays(-1), 15, ONE);

    // test on the billing cycle day
    testCalculateNumberOfBillingCycles(startDate, oneCycleLater, 15, TWO);

    // test just after the billing cycle day
    testCalculateNumberOfBillingCycles(startDate, oneCycleLater.plusDays(1), 15, TWO);
}

From source file:org.killbill.billing.invoice.proRations.inAdvance.GenericProRationTestBase.java

License:Apache License

@Test(groups = "fast")
public void testSinglePlan_StartingMidFebruary() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 15);
    final LocalDate targetDate = startDate.plus(getBillingPeriod().getPeriod());

    testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}

From source file:org.killbill.billing.invoice.proRations.inAdvance.GenericProRationTestBase.java

License:Apache License

@Test(groups = "fast")
public void testSinglePlan_StartingMidFebruaryOfLeapYear() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2012, 2, 15);
    final LocalDate targetDate = startDate.plus(getBillingPeriod().getPeriod());

    testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}