Returns an object of the same type as this object with the specified period added.
This method returns a new object based on this one with the specified period added.
For example, on a LocalDate, this could be used to add a number of years, months or days.
The returned object will have the same observable type as this object.
In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then adding one month would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
amountToAdd | the amount of the specified unit to add, may be negative | |
unit | the unit of the amount to add, not null |
DateTimeException | if the unit cannot be added | |
UnsupportedTemporalTypeException | if the unit is not supported | |
ArithmeticException | if numeric overflow occurs |
@implSpec
Implementations must check and handle all units defined in ChronoUnit.
If the unit is supported, then the addition must be performed.
If unsupported, then an UnsupportedTemporalTypeException must be thrown.
If the unit is not a ChronoUnit, then the result of this method
is obtained by invoking TemporalUnit.addTo(Temporal, long)
passing this as the first argument.
Implementations must not alter this object.
Instead, an adjusted copy of the original must be returned.
This provides equivalent, safe behavior for immutable and mutable implementations.
Diagram: LocalTime