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.
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]');
}