es.date.set-year.js 674 B

1234567891011121314151617181920
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var uncurryThis = require('../internals/function-uncurry-this');
  4. var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
  5. var DatePrototype = Date.prototype;
  6. var getTime = uncurryThis(DatePrototype.getTime);
  7. var setFullYear = uncurryThis(DatePrototype.setFullYear);
  8. // `Date.prototype.setYear` method
  9. // https://tc39.es/ecma262/#sec-date.prototype.setyear
  10. $({ target: 'Date', proto: true }, {
  11. setYear: function setYear(year) {
  12. // validate
  13. getTime(this);
  14. var yi = toIntegerOrInfinity(year);
  15. var yyyy = 0 <= yi && yi <= 99 ? yi + 1900 : yi;
  16. return setFullYear(this, yyyy);
  17. }
  18. });