diff --git a/lib/util.js b/lib/util.js index d430bfd23d..aa592eb41f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -348,7 +348,11 @@ function formatValue(ctx, value, recurseTimes) { return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); } if (isDate(value)) { - return ctx.stylize(Date.prototype.toISOString.call(value), 'date'); + if (Number.isNaN(value.getTime())) { + return ctx.stylize(value.toString(), 'date'); + } else { + return ctx.stylize(Date.prototype.toISOString.call(value), 'date'); + } } if (isError(value)) { return formatError(value); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index d2af5014b2..4e1d5a2d1b 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -12,8 +12,9 @@ assert.equal(util.inspect(function() {}), '[Function]'); assert.equal(util.inspect(undefined), 'undefined'); assert.equal(util.inspect(null), 'null'); assert.equal(util.inspect(/foo(bar\n)?/gi), '/foo(bar\\n)?/gi'); -assert.equal(util.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')), +assert.strictEqual(util.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')), new Date('2010-02-14T12:48:40+01:00').toISOString()); +assert.strictEqual(util.inspect(new Date('')), (new Date('')).toString()); assert.equal(util.inspect('\n\u0001'), "'\\n\\u0001'");