Example usage for org.joda.time DateMidnight plus

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

Introduction

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

Prototype

public DateMidnight plus(ReadablePeriod period) 

Source Link

Document

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

Usage

From source file:com.billing.ng.entities.BillingCycle.java

License:Open Source License

/**
 * The initial starting instant of the entire billing cycle. The start instant is
 * the first instance of the cycle start day after (or equal to) the cycle start date.
 *
 * @return starting instant of this billing cycle
 *///from ww w  .j a  v  a 2 s .  c  o  m
public DateMidnight getStartInstant() {
    DateMidnight start = new DateMidnight(getStart());
    Period period = getBillingPeriod().getPeriodOfTime();

    // first possible start date for a period
    DateMidnight calculated = getCycleStartDay() != LAST_DAY_OF_MONTH
            ? start.dayOfMonth().setCopy(getCycleStartDay())
            : start.dayOfMonth().withMaximumValue();

    // increment by billing period interval until a valid start date is found
    while (calculated.isBefore(start)) {
        calculated = calculated.plus(period);
    }
    return calculated;
}

From source file:com.billing.ng.entities.CurrentBillingCycle.java

License:Open Source License

/**
 * Calculate the start date of the current cycle.
 *
 * @param period billing period//from w  w  w.  j  av  a 2  s .  c o  m
 * @param billingStart billing cycle start
 * @param cycleNumber current cycle number
 * @return calculated cycle start date
 */
public static DateMidnight calculateCycleStart(BillingPeriod period, DateMidnight billingStart,
        Integer cycleNumber) {
    Period increment = period.getPeriodOfTime(cycleNumber); // elapsed period of time for cycle number
    return billingStart.plus(increment);
}

From source file:com.billing.ng.entities.CurrentBillingCycle.java

License:Open Source License

/**
 * Calculate the end date of the current cycle.
 *
 * @param period billing period//from   w  w w.j a va 2 s .  c o m
 * @param cycleStart calculated start date for the current cycle
 * @return calculated cycle end date
 */
public static DateMidnight calculateCycleEnd(BillingPeriod period, DateMidnight cycleStart) {
    Period increment = period.getPeriodOfTime(); // single period
    return cycleStart.plus(increment);
}