From 485a1b819acbd171cf72c9075bfbeb589e53dffa Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 11 Aug 2015 12:19:22 +0200 Subject: [PATCH] src: fix localtime in case NaN is passed - Check for the validity of the argument in JS-land. - The test localtime() in exports.js was failing because struct tm *timeinfo in NAN_METHOD(Localtime) was being created correctly. --- index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 088efe3..562c25d 100644 --- a/index.js +++ b/index.js @@ -39,9 +39,19 @@ exports.currentTimezone = process.env.TZ; */ exports.time = bindings.time; -exports.localtime = bindings.localtime; exports.mktime = bindings.mktime; +/** + * Check if the first argument is NaN and just return in case it is. + */ +exports.localtime = function localtime() { + if ((arguments[0] !== undefined) && isNaN(arguments[0])) { + return { invalid: true }; + } else { + return bindings.localtime.apply(null, arguments); + } +}; + /** * A "hack" of sorts to force getting our own Date instance. * Otherwise, in normal cases, the global Natives are shared between