/** * Returns a copy of this {@code OffsetDateTime} with the specified number of years added. * <p> * This method adds the specified amount to the years field in three steps: * <ol> * <li>Add the input years to the year field</li> * <li>Check if the resulting date would be invalid</li> * <li>Adjust the day-of-month to the last valid day if necessary</li> * </ol> * <p> * For example, 2008-02-29 (leap year) plus one year would result in the * invalid date 2009-02-29 (standard year). Instead of returning an invalid * result, the last valid day of the month, 2009-02-28, is selected instead. * <p> * This instance is immutable and unaffected by this method call. * * @param int $years the years to add, may be negative * @return OffsetDateTime an {@code OffsetDateTime} based on this date-time with the years added, not null * @throws DateTimeException if the result exceeds the supported date range */ public function plusYears($years) { return $this->_with($this->dateTime->plusYears($years), $this->offset); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified number of years added. * <p> * This operates on the local time-line, * {@link LocalDateTime#plusYears(long) adding years} to the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param int $years the years to add, may be negative * @return ZonedDateTime a {@code ZonedDateTime} based on this date-time with the years added, not null * @throws DateTimeException if the result exceeds the supported date range */ public function plusYears($years) { return $this->resolveLocal($this->dateTime->plusYears($years)); }