Example usage for org.joda.time DateTime plusMonths

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

Introduction

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

Prototype

public DateTime plusMonths(int months) 

Source Link

Document

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

Usage

From source file:org.mifos.platform.cashflow.service.CashFlowServiceImpl.java

License:Open Source License

@Override
public CashFlowBoundary getCashFlowBoundary(DateTime firstInstallmentDueDate, DateTime lastInstallmentDueDate) {
    DateTime monthAfterLastInstallment = lastInstallmentDueDate
            .plusMonths(EXTRA_DURATION_FOR_CASH_FLOW_SCHEDULE).withDayOfMonth(FIRST_DAY);
    DateTime monthBeforeFirstInstallment = firstInstallmentDueDate
            .minusMonths(EXTRA_DURATION_FOR_CASH_FLOW_SCHEDULE).withDayOfMonth(FIRST_DAY);
    int numberOfMonths = Months.monthsBetween(monthBeforeFirstInstallment, monthAfterLastInstallment)
            .getMonths() + 1;//from   w ww .java 2s  .c  o m
    return new CashFlowBoundary(monthBeforeFirstInstallment.getMonthOfYear(),
            monthBeforeFirstInstallment.getYear(), numberOfMonths);
}

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

License:Open Source License

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

From source file:org.n52.iceland.util.DateTimeHelper.java

License:Open Source License

/**
 * Set the time object to the end values (seconds, minutes, hours, days,..)
 * if the time Object has not all values
 *
 * @param dateTime//  w  ww.  j ava  2s  .com
 *            Time object
 * @param isoTimeLength
 *            Length of the time object
 * @return Modified time object.
 */
public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(final DateTime dateTime,
        final int isoTimeLength) {
    switch (isoTimeLength) {
    // year
    case YEAR:
        return dateTime.plusYears(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month
    case YEAR_MONTH:
        return dateTime.plusMonths(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month, day
    case YEAR_MONTH_DAY:
        return dateTime.plusDays(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month, day, hour
    case YEAR_MONTH_DAY_HOUR:
        return dateTime.plusHours(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month, day, hour, minute
    case YEAR_MONTH_DAY_HOUR_MINUTE:
        return dateTime.plusMinutes(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month, day, hour, minute, second
    case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND:
        return dateTime.plusSeconds(ONE_VALUE).minusMillis(ONE_VALUE);
    default:
        return dateTime;
    }
}

From source file:org.n52.oxf.ses.adapter.SESRequestBuilder_00.java

License:Open Source License

private Calendar createTerminationTime(String stringTime) {
    DateTime date = new DateTime(stringTime);
    DateTime now = new DateTime();
    if (date.isAfter(now)) {
        return date.toCalendar(Locale.getDefault());
    }//from  w ww.j a  v  a2 s  .co  m

    /*
     * default to one month from now
     */
    return now.plusMonths(1).toCalendar(Locale.getDefault());
}

From source file:org.n52.shetland.util.DateTimeHelper.java

License:Apache License

/**
 * Set the time object to the end values (seconds, minutes, hours, days,..)
 * if the time Object has not all values
 *
 * @param dateTime//www . j  ava  2s . c  o m
 *            Time object
 * @param isoTimeLength
 *            Length of the time object
 * @return Modified time object.
 */
public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(DateTime dateTime,
        int isoTimeLength) {
    switch (isoTimeLength) {
    case YEAR:
        return dateTime.plusYears(1).minusMillis(1);
    case YEAR_MONTH:
        return dateTime.plusMonths(1).minusMillis(1);
    case YEAR_MONTH_DAY:
        return dateTime.plusDays(1).minusMillis(1);
    case YEAR_MONTH_DAY_HOUR:
        return dateTime.plusHours(1).minusMillis(1);
    case YEAR_MONTH_DAY_HOUR_MINUTE:
        return dateTime.plusMinutes(1).minusMillis(1);
    case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND:
        return dateTime.plusSeconds(1).minusMillis(1);
    default:
        return dateTime;
    }
}

From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java

License:Apache License

private static DateTime plusDurationAsExpression(DateTime origin, String duration) {
    int k = getFactor(duration);
    switch (duration.substring(duration.length() - 1, duration.length())) {
    case "s":
        return origin.plusSeconds(k);
    case "m":
        return origin.plusMinutes(k);
    case "h":
        return origin.plusHours(k);
    case "d":
        return origin.plusDays(k);
    case "w":
        return origin.plusWeeks(k);
    case "M":
        return origin.plusMonths(k);
    case "y":
        return origin.plusYears(k);
    }/* ww w  .  j  a va  2 s. com*/
    return invalid(duration);
}

From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java

License:Apache License

private static DateTime plusDurationAsNoun(DateTime origin, String duration) {
    switch (duration.toLowerCase()) {
    case "second":
        return origin.plusSeconds(1);
    case "minute":
        return origin.plusMinutes(1);
    case "hour":
        return origin.plusHours(1);
    case "day":
        return origin.plusDays(1);
    case "week":
        return origin.plusWeeks(1);
    case "month":
        return origin.plusMonths(1);
    case "quarter":
        return origin.plusMonths(3);
    case "year":
        return origin.plusYears(1);
    }//from  w ww  .  j av a  2 s  . c om
    return invalid(duration);
}

From source file:org.obm.imap.archive.services.SchedulingDatesService.java

License:Open Source License

private DateTime nextTreatmentDateOnLastDayOfMonth(DateTime currentDateTime,
        DateTime currentDateWithScheduledTime) {
    DateTime dayOfMonth = lastDayOfMonth(currentDateWithScheduledTime);

    if (dayOfMonth.isAfter(currentDateTime)) {
        return dayOfMonth;
    }//from  w  w  w .  j a  v a  2 s.c o  m
    // currentDateTime is at the end of the month, but on a higher time -> next month 
    return lastDayOfMonth(currentDateWithScheduledTime.plusMonths(1));
}

From source file:org.obm.imap.archive.services.SchedulingDatesService.java

License:Open Source License

private DateTime lastDayOfMonth(DateTime currentDateWithScheduledTime) {
    return currentDateWithScheduledTime.plusMonths(1).withDayOfMonth(1).minusDays(1);
}

From source file:org.obm.imap.archive.services.SchedulingDatesService.java

License:Open Source License

private DateTime nextTreatmentDateCommonDayOfMonth(SchedulingConfiguration schedulingConfiguration,
        DateTime currentDateTime, DateTime currentDateWithScheduledTime) {
    DateTime dayOfMonth = currentDateWithScheduledTime
            .withDayOfMonth(schedulingConfiguration.getDayOfMonth().getDayIndex());

    if (dayOfMonth.isAfter(currentDateTime)) {
        return dayOfMonth;
    }/* w w  w .j a  v  a 2s. c o m*/
    return dayOfMonth.plusMonths(1);
}