From 2cfb20c2d0b398f85921a865c97d0c8f12ef9d76 Mon Sep 17 00:00:00 2001 From: Alex Lau Date: Fri, 1 Apr 2016 18:31:28 -0700 Subject: [PATCH] Only set timezone for valid dates in constructor --- index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 088efe3..188497e 100644 --- a/index.js +++ b/index.js @@ -578,12 +578,14 @@ function Date (year, month, day, hour, minute, second, millisecond, timezone) { case 7: d = new _Date(year, month, day, hour, minute, second, millisecond); break; } - if (timezone) { - // set time given timezone relative to the currently set local time - // (changing the internal "time" milliseconds value unless ms specified) - d.setTimezone(timezone, !(argc == 1 && typeof year === 'number')); - } else { - d.setTimezone(exports.currentTimezone); + if (!isNaN(d)) { + if (timezone) { + // set time given timezone relative to the currently set local time + // (changing the internal "time" milliseconds value unless ms specified) + d.setTimezone(timezone, !(argc == 1 && typeof year === 'number')); + } else { + d.setTimezone(exports.currentTimezone); + } } return d; }