/** * Returns a copy of this {@code OffsetDateTime} with the day-of-year altered. * <p> * The time and offset do not affect the calculation and will be the same in the result. * If the resulting {@code OffsetDateTime} is invalid, an exception is thrown. * <p> * This instance is immutable and unaffected by this method call. * * @param int $dayOfYear the day-of-year to set in the result, from 1 to 365-366 * @return OffsetDateTime an {@code OffsetDateTime} based on this date with the requested day, not null * @throws DateTimeException if the day-of-year value is invalid, * or if the day-of-year is invalid for the year */ public function withDayOfYear($dayOfYear) { return $this->_with($this->dateTime->withDayOfYear($dayOfYear), $this->offset); }
/** * Returns a copy of this {@code ZonedDateTime} with the day-of-year altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withDayOfYear(int) changing the day-of-year} of 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 $dayOfYear the day-of-year to set in the result, from 1 to 365-366 * @return ZonedDateTime a {@code ZonedDateTime} based on this date with the requested day, not null * @throws DateTimeException if the day-of-year value is invalid, * or if the day-of-year is invalid for the year */ public function withDayOfYear($dayOfYear) { return $this->resolveLocal($this->dateTime->withDayOfYear($dayOfYear)); }