/** * Adds supplied multiples of this interval to the supplied instant. * * @param instant the instant that needs to be added to. * @param multiple the multiple value * @throws IllegalArgumentException if multiple is less than one. * @throws UnsupportedOperationException if the function is invoked on an {@link #INFINITE} * object * */ public DateTime plus(DateTime instant, int multiple) { if (this == INFINITE) { throw new IllegalStateException( "plus() function is not supported on an infinite TimeInterval" ); } else if (this == ZERO) { return instant; } validateMultiple(multiple); if (type == null) { return instant.plus(multiple * getLength()); } else { return instant.plus( type.toPeriod( FieldUtils.safeMultiplyToInt(multiple, getLength()) ) ); } }
/** * Subtracts the supplied multiples of this interval from the supplied instant. If the * TimeInterval is {@link #INFINITE} the epoch in the timezone of {@code instant} is returned * * @param instant the instant to subtract from * @param multiple the multiple value * @throws IllegalArgumentException if multiple is less than one. */ public DateTime minus(DateTime instant, int multiple) { if (this == INFINITE) { throw new IllegalStateException( "minus() function is not supported on an infinite TimeInterval" ); } else if (this == ZERO) { return instant; } validateMultiple(multiple); if (type == null) { return instant.minus(multiple * getLength()); } else { return instant.minus(type.toPeriod( FieldUtils.safeMultiplyToInt(multiple, getLength()))); } }