From 7cda52696af52bcb537d391512ac32128932445a Mon Sep 17 00:00:00 2001 From: Rumkin Date: Fri, 29 Apr 2016 13:47:09 +0300 Subject: [PATCH 1/2] fix throwing RangeError on invalid date output Invalid date value throws RangeError on output with `console.log` or `util.inspect`. --- lib/util.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 63d6d0f3c865af..32a376e04ceddd 100644 --- a/lib/util.js +++ b/lib/util.js @@ -304,7 +304,12 @@ 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 (value.toString() === 'Invalid Date') { + return ctx.stylize('Invalid Date', 'date'); + } + else { + return ctx.stylize(Date.prototype.toISOString.call(value), 'date'); + } } if (isError(value)) { return formatError(value); From b23061713ea4c52d1280ca5f5d015aa92a62d529 Mon Sep 17 00:00:00 2001 From: Rumkin Date: Fri, 29 Apr 2016 19:25:59 +0300 Subject: [PATCH 2/2] fix code style --- lib/util.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index 32a376e04ceddd..02a9b64c90f53e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -306,8 +306,7 @@ function formatValue(ctx, value, recurseTimes) { if (isDate(value)) { if (value.toString() === 'Invalid Date') { return ctx.stylize('Invalid Date', 'date'); - } - else { + } else { return ctx.stylize(Date.prototype.toISOString.call(value), 'date'); } }