es.date.to-string.js 772 B

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