src/LocalDateTime.php
public function withYear(int $year) : LocalDateTime
    {
        $date = $this->date->withYear($year);

        if ($date === $this->date) {
            return $this;
        }

        return new LocalDateTime($date, $this->time);
    }
public function withYear(int $year) : LocalDateTime
    {
        $date = $this->date->withYear($year);

        if ($date === $this->date) {
            return $this;
        }

        return new LocalDateTime($date, $this->time);
    }
public function withYear ( int $ year ) : LocalDateTime { $ date = $ this -> date -> withYear ( $ year ) ; if ( $ date === $ this -> date ) { return $ this ; } return new LocalDateTime ( $ date , $ this -> time ) ; }
Returns a copy of this LocalDateTime with the year altered.

If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.

@param int $year

@return LocalDateTime

@throws DateTimeException If the year is outside the valid range.
Returns a copy of this LocalDateTime with the year altered .