Check if object is date.
//As an alternative to duck typing via
typeof date.getMonth === 'function'
//you can use the instanceof operator, i.e.
date instanceof Date
//This will fail if objects are passed across frame boundaries.
//A work-around for this is to check the object's class via.
Object.prototype.toString.call(date) === '[object Date]'