ToDateString.js 546 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var $Date = GetIntrinsic('%Date%');
  5. var $String = GetIntrinsic('%String%');
  6. var $isNaN = require('../helpers/isNaN');
  7. var Type = require('./Type');
  8. // https://262.ecma-international.org/6.0/#sec-todatestring
  9. module.exports = function ToDateString(tv) {
  10. if (Type(tv) !== 'Number') {
  11. throw new $TypeError('Assertion failed: `tv` must be a Number');
  12. }
  13. if ($isNaN(tv)) {
  14. return 'Invalid Date';
  15. }
  16. return $String(new $Date(tv));
  17. };