2.1.164 [ECMA-262-1999] Section B.2.5, Date.prototype.setYear (year)

V0265:

When the setYear method is called with one argument year the following steps are taken:

(The bulleted step is added before step 1)

  • __If the argument year is not present, throw a TypeError exception.__

  1. Let t be the result of LocalTime(this time value); but if this time value is NaN, let t be +0.

  2. Call ToNumber(year).

  3. If Result(2) is NaN, set the [[Value]] property of the this value to NaN and return NaN.

  4. If Result(2) is not NaN and 0 ≤ ToInteger(Result(2)) ≤ 99 then Result(4) is ToInteger(Result(2)) #+ 1900#. Otherwise, Result(4) is Result(2).

  5. Compute MakeDay(Result(4), MonthFromTime(t), DateFromTime(t)).

  6. Compute UTC(MakeDate(Result(5), TimeWithinDay(t))).

  7. Set the [[Value]] property of the this value to TimeClip(Result(6)).

  8. Return the value of the [[Value]] property of the this value.

For JScript 5.x, Date.prototype.setYear is functionally identical to Date.prototype.setFullYear.