Skip to content

Commit

Permalink
fix: Date.isDate to exclude NaN dates
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Mar 28, 2018
1 parent f1be285 commit 3b61bc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion date/is-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
var objToString = Object.prototype.toString, id = objToString.call(new Date());

module.exports = function (value) {
return (value && (value instanceof Date || objToString.call(value) === id)) || false;
return (
(value && !isNaN(value) && (value instanceof Date || objToString.call(value) === id)) ||
false
);
};
2 changes: 1 addition & 1 deletion date/valid-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
var isDate = require("./is-date");

module.exports = function (value) {
if (!isDate(value) || isNaN(value)) throw new TypeError(value + " is not valid Date object");
if (!isDate(value)) throw new TypeError(value + " is not valid Date object");
return value;
};

0 comments on commit 3b61bc6

Please sign in to comment.