MakeFullYear.js 595 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var ToIntegerOrInfinity = require('./ToIntegerOrInfinity');
  4. var isNaN = require('../helpers/isNaN');
  5. // https://262.ecma-international.org/15.0/#sec-makefullyear
  6. module.exports = function MakeFullYear(year) {
  7. if (typeof year !== 'number') {
  8. throw new $TypeError('Assertion failed: `year` must be a Number');
  9. }
  10. if (isNaN(year)) {
  11. return NaN; // step 1
  12. }
  13. var truncated = ToIntegerOrInfinity(year); // step 2
  14. if (0 <= truncated && truncated <= 99) {
  15. return 1900 + truncated; // step 3
  16. }
  17. return truncated; // step 4
  18. };