ToDateString.js 514 B

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