Search in sources :

Example 11 with DurationFieldType

use of org.joda.time.DurationFieldType in project joda-time by JodaOrg.

the class BasePeriod method addPeriodInto.

/**
     * Adds the fields from another period.
     * 
     * @param values  the array of values to update
     * @param period  the period to add from, not null
     * @return the updated values
     * @throws IllegalArgumentException if an unsupported field's value is non-zero
     */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        if (value != 0) {
            int index = indexOf(type);
            if (index == -1) {
                throw new IllegalArgumentException("Period does not support field '" + type.getName() + "'");
            } else {
                values[index] = FieldUtils.safeAdd(getValue(index), value);
            }
        }
    }
    return values;
}
Also used : DurationFieldType(org.joda.time.DurationFieldType)

Aggregations

DurationFieldType (org.joda.time.DurationFieldType)11 ScaledDurationField (org.joda.time.field.ScaledDurationField)4 DateTimeFieldType (org.joda.time.DateTimeFieldType)3 Period (org.joda.time.Period)3 DateTime (org.joda.time.DateTime)1 MutablePeriod (org.joda.time.MutablePeriod)1 ReadWritablePeriod (org.joda.time.ReadWritablePeriod)1 PeriodFormatter (org.joda.time.format.PeriodFormatter)1