Skip to content

Commit 93d6b5f

Browse files
Xotic750cjihrig
Xotic750
authored andcommitted
util: use consistent Dates in inspect()
Fix: #4314 PR-URL: #4318 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent e5774c9 commit 93d6b5f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function formatValue(ctx, value, recurseTimes) {
269269
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
270270
}
271271
if (isDate(value)) {
272-
return ctx.stylize(Date.prototype.toString.call(value), 'date');
272+
return ctx.stylize(Date.prototype.toISOString.call(value), 'date');
273273
}
274274
if (isError(value)) {
275275
return formatError(value);
@@ -390,7 +390,7 @@ function formatValue(ctx, value, recurseTimes) {
390390

391391
// Make dates with properties first say the date
392392
if (isDate(value)) {
393-
base = ' ' + Date.prototype.toUTCString.call(value);
393+
base = ' ' + Date.prototype.toISOString.call(value);
394394
}
395395

396396
// Make error with message first say the error

test/parallel/test-util-inspect.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ assert.equal(util.inspect(undefined), 'undefined');
1313
assert.equal(util.inspect(null), 'null');
1414
assert.equal(util.inspect(/foo(bar\n)?/gi), '/foo(bar\\n)?/gi');
1515
assert.equal(util.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')),
16-
new Date('2010-02-14T12:48:40+01:00').toString());
16+
new Date('2010-02-14T12:48:40+01:00').toISOString());
1717

1818
assert.equal(util.inspect('\n\u0001'), "'\\n\\u0001'");
1919

@@ -220,7 +220,7 @@ assert.equal(util.inspect(value), '{ /123/gi aprop: 42 }');
220220
// Dates with properties
221221
value = new Date('Sun, 14 Feb 2010 11:48:40 GMT');
222222
value.aprop = 42;
223-
assert.equal(util.inspect(value), '{ Sun, 14 Feb 2010 11:48:40 GMT aprop: 42 }'
223+
assert.equal(util.inspect(value), '{ 2010-02-14T11:48:40.000Z aprop: 42 }'
224224
);
225225

226226
// test the internal isDate implementation
@@ -313,6 +313,12 @@ assert.doesNotThrow(function() {
313313
util.inspect(d);
314314
});
315315

316+
assert.doesNotThrow(function() {
317+
var d = new Date();
318+
d.toISOString = null;
319+
util.inspect(d);
320+
});
321+
316322
assert.doesNotThrow(function() {
317323
var r = /regexp/;
318324
r.toString = null;

0 commit comments

Comments
 (0)