Example usage for org.joda.time Period withMonths

List of usage examples for org.joda.time Period withMonths

Introduction

In this page you can find the example usage for org.joda.time Period withMonths.

Prototype

public Period withMonths(int months) 

Source Link

Document

Returns a new period with the specified number of months.

Usage

From source file:influent.server.utilities.DateTimeParser.java

License:MIT License

/**
 * @see http://joda-time.sourceforge.net/apidocs/org/joda/time/Period.html#normalizedStandard()
 *//*from  w ww  .  j a  va2 s  .c o m*/
public static Period normalize(Period period) {
    long millis = period.getMillis();
    millis += period.getSeconds() * DateTimeConstants.MILLIS_PER_SECOND;
    millis += period.getMinutes() * DateTimeConstants.MILLIS_PER_MINUTE;
    millis += period.getHours() * DateTimeConstants.MILLIS_PER_HOUR;
    millis += period.getDays() * DateTimeConstants.MILLIS_PER_DAY;
    millis += period.getWeeks() * DateTimeConstants.MILLIS_PER_WEEK;

    Period result = new Period(millis, DateTimeUtils.getPeriodType(PeriodType.standard()),
            ISOChronology.getInstanceUTC());
    int years = period.getYears();
    int months = period.getMonths();

    if (years != 0 || months != 0) {
        years = FieldUtils.safeAdd(years, months / 12);
        months = months % 12;
        if (years != 0) {
            result = result.withYears(years);
        }
        if (months != 0) {
            result = result.withMonths(months);
        }
    }

    return result;
}

From source file:nz.co.gregs.dbvolution.internal.datatypes.DateRepeatImpl.java

License:Apache License

/**
 *
 * @param intervalStr/* w w  w .  ja va 2 s.  c o  m*/
 * @return the DateRepeat value represented by the String value
 */
public static Period parseDateRepeatFromGetString(String intervalStr) {
    if (intervalStr == null || intervalStr.length() == 0) {
        return null;
    }
    System.out.println("DBV INTERVAL: " + intervalStr);
    Period interval = new Period();
    interval = interval.withYears(getYearPart(intervalStr));
    interval = interval.withMonths(getMonthPart(intervalStr));
    interval = interval.withDays(getDayPart(intervalStr));
    interval = interval.withHours(getHourPart(intervalStr));
    interval = interval.withMinutes(getMinutePart(intervalStr));
    interval = interval.withSeconds(getSecondPart(intervalStr));
    interval = interval.withMillis(getMillisecondPart(intervalStr));
    return interval;
}