From 44574bc39b93c96d9bd15e79757cf2eec501ac3a Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 30 Aug 2011 23:13:45 -0700 Subject: [PATCH] util: improve util.isDate() function The old implementation was fragile. i.e. node-time is an example of a user-land module that exports an extended Date object (with a few added functions on it's own Date object's prototype). In that case, the old check fails. --- lib/util.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/util.js b/lib/util.js index 1a04190..f47e39f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -332,11 +332,8 @@ function isRegExp(re) { function isDate(d) { - if (d instanceof Date) return true; - if (typeof d !== 'object') return false; - var properties = Date.prototype && Object.getOwnPropertyNames(Date.prototype); - var proto = d.__proto__ && Object.getOwnPropertyNames(d.__proto__); - return JSON.stringify(proto) === JSON.stringify(properties); + return d instanceof Date || + (typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]'); } -- 2.7.4