Skip to content

Commit

Permalink
If @@toStringTag is not present, use the old-school `Object#toStrin…
Browse files Browse the repository at this point in the history
…g` test.
  • Loading branch information
ljharb committed Sep 27, 2015
1 parent 35cbff7 commit c03afce
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions index.js
@@ -1,12 +1,20 @@
'use strict';

var getDay = Date.prototype.getDay;

module.exports = function isDateObject(value) {
var tryDateObject = function tryDateObject(value) {
try {
getDay.call(value);
return true;
} catch (e) {
return false;
}
};

var toStr = Object.prototype.toString;
var dateClass = '[object Date]';
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';

module.exports = function isDateObject(value) {
if (typeof value !== 'object' || value === null) { return false; }
return hasToStringTag ? tryDateObject(value) : toStr.call(value) === dateClass;
};

0 comments on commit c03afce

Please sign in to comment.