src/YearWeek.php
public function withYear(int $year) : YearWeek
    {
        if ($year === $this->year) {
            return $this;
        }

        Field\Year::check($year);

        $week = $this->week;

        if ($week === 53 && ! Field\WeekOfYear::is53WeekYear($year)) {
            $week = 52;
        }

        return new YearWeek($year, $week);
    }
public function withYear(int $year) : YearWeek
    {
        if ($year === $this->year) {
            return $this;
        }

        Field\Year::check($year);

        $week = $this->week;

        if ($week === 53 && ! Field\WeekOfYear::is53WeekYear($year)) {
            $week = 52;
        }

        return new YearWeek($year, $week);
    }
public function withYear ( int $ year ) : YearWeek { if ( $ year === $ this -> year ) { return $ this ; } Field \ Year :: check ( $ year ) ; $ week = $ this -> week ; if ( $ week === 53 && ! Field \ WeekOfYear :: is53WeekYear ( $ year ) ) { $ week = 52 ; } return new YearWeek ( $ year , $ week ) ; }
Returns a copy of this YearWeek with the year altered.

If the week is 53 and the new year does not have 53 weeks, the week will be adjusted to be 52.

@param int $year

@return YearWeek

@throws DateTimeException If the year is not valid.
Returns a copy of this YearWeek with the year altered .