| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- "use strict";
- exports.isValid = isValid;
- var _index = require("./isDate.js");
- var _index2 = require("./toDate.js");
- /**
- * @name isValid
- * @category Common Helpers
- * @summary Is the given date valid?
- *
- * @description
- * Returns false if argument is Invalid Date and true otherwise.
- * Argument is converted to Date using `toDate`. See [toDate](https://date-fns.org/docs/toDate)
- * Invalid Date is a Date, whose time value is NaN.
- *
- * Time value of Date: http://es5.github.io/#x15.9.1.1
- *
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
- *
- * @param date - The date to check
- *
- * @returns The date is valid
- *
- * @example
- * // For the valid date:
- * const result = isValid(new Date(2014, 1, 31))
- * //=> true
- *
- * @example
- * // For the value, convertable into a date:
- * const result = isValid(1393804800000)
- * //=> true
- *
- * @example
- * // For the invalid date:
- * const result = isValid(new Date(''))
- * //=> false
- */
- function isValid(date) {
- if (!(0, _index.isDate)(date) && typeof date !== "number") {
- return false;
- }
- const _date = (0, _index2.toDate)(date);
- return !isNaN(Number(_date));
- }
|