es.date.to-string.js 757 B

12345678910111213141516171819
  1. // TODO: Remove from `core-js@4`
  2. var uncurryThis = require('../internals/function-uncurry-this');
  3. var defineBuiltIn = require('../internals/define-built-in');
  4. var DatePrototype = Date.prototype;
  5. var INVALID_DATE = 'Invalid Date';
  6. var TO_STRING = 'toString';
  7. var nativeDateToString = uncurryThis(DatePrototype[TO_STRING]);
  8. var thisTimeValue = uncurryThis(DatePrototype.getTime);
  9. // `Date.prototype.toString` method
  10. // https://tc39.es/ecma262/#sec-date.prototype.tostring
  11. if (String(new Date(NaN)) != INVALID_DATE) {
  12. defineBuiltIn(DatePrototype, TO_STRING, function toString() {
  13. var value = thisTimeValue(this);
  14. // eslint-disable-next-line no-self-compare -- NaN check
  15. return value === value ? nativeDateToString(this) : INVALID_DATE;
  16. });
  17. }