Skip to content

Commit c03afce

Browse files
committed
If @@toStringTag is not present, use the old-school Object#toString test.
1 parent 35cbff7 commit c03afce

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
'use strict';
22

33
var getDay = Date.prototype.getDay;
4-
5-
module.exports = function isDateObject(value) {
4+
var tryDateObject = function tryDateObject(value) {
65
try {
76
getDay.call(value);
87
return true;
98
} catch (e) {
109
return false;
1110
}
1211
};
12+
13+
var toStr = Object.prototype.toString;
14+
var dateClass = '[object Date]';
15+
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
16+
17+
module.exports = function isDateObject(value) {
18+
if (typeof value !== 'object' || value === null) { return false; }
19+
return hasToStringTag ? tryDateObject(value) : toStr.call(value) === dateClass;
20+
};

0 commit comments

Comments
 (0)