Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
util: improve util.isDate() function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TooTallNate authored and bnoordhuis committed Sep 2, 2011
1 parent 2b0a7d6 commit 44574bc
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/util.js
Expand Up @@ -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]');
}


Expand Down

0 comments on commit 44574bc

Please sign in to comment.