es.date.to-string.js 689 B

123456789101112131415161718
  1. var uncurryThis = require('../internals/function-uncurry-this');
  2. var redefine = require('../internals/redefine');
  3. var DatePrototype = Date.prototype;
  4. var INVALID_DATE = 'Invalid Date';
  5. var TO_STRING = 'toString';
  6. var un$DateToString = uncurryThis(DatePrototype[TO_STRING]);
  7. var getTime = uncurryThis(DatePrototype.getTime);
  8. // `Date.prototype.toString` method
  9. // https://tc39.es/ecma262/#sec-date.prototype.tostring
  10. if (String(new Date(NaN)) != INVALID_DATE) {
  11. redefine(DatePrototype, TO_STRING, function toString() {
  12. var value = getTime(this);
  13. // eslint-disable-next-line no-self-compare -- NaN check
  14. return value === value ? un$DateToString(this) : INVALID_DATE;
  15. });
  16. }