From c03afce001368b29eb929900075749b113a252c8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 27 Sep 2015 06:13:04 -0700 Subject: [PATCH] If `@@toStringTag` is not present, use the old-school `Object#toString` test. --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1f3ee87..fe0d7ec 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ 'use strict'; var getDay = Date.prototype.getDay; - -module.exports = function isDateObject(value) { +var tryDateObject = function tryDateObject(value) { try { getDay.call(value); return true; @@ -10,3 +9,12 @@ module.exports = function isDateObject(value) { 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; +};