es.date.to-string.js 605 B

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