UNPKG

date-is-valid

Version:
23 lines (21 loc) 454 B
"use strict"; /** * dateIsValid * Check if a date is invalid or not. * * @name dateIsValid * @function * @param {Date | ISOString} d The input date. * @returns {Boolean} `true` if the date is valid, `false` otherwise. */ module.exports = function dateIsValid(d) { var t = NaN; try { t = d.getTime(); } catch (error) { if (typeof d === "string") { t = Date.parse(d); } } return t === t; };