You can add, subtract, multiply, and divide dates and durations in a number of ways to produce a variety of date or duration information. Methods are defined for any combination of date and duration, with any operation that makes sense, and the return value is of the appropriate type.
For example, a method is defined that subtracts one date from another, and returns a duration, but there is no method for adding two dates together, since dates cannot be summed in any sensible way. However, there are methods for adding dates and durations which return dates.
Note that some addition and subtraction operations involving dates and instances of <year/month-duration> can cause errors where the result is a date that does not exist in the calendar. For example, adding one month to January 30th.
The table below summarizes the methods defined for each arithmetic operation, for different combinations of date and duration arguments, together with their return values.
Op | Argument 1 | Argument 2 | Return value |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|