isPast.js 713 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. exports.isPast = isPast;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name isPast
  6. * @category Common Helpers
  7. * @summary Is the given date in the past?
  8. * @pure false
  9. *
  10. * @description
  11. * Is the given date in the past?
  12. *
  13. * @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).
  14. *
  15. * @param date - The date to check
  16. *
  17. * @returns The date is in the past
  18. *
  19. * @example
  20. * // If today is 6 October 2014, is 2 July 2014 in the past?
  21. * const result = isPast(new Date(2014, 6, 2))
  22. * //=> true
  23. */
  24. function isPast(date) {
  25. return +(0, _index.toDate)(date) < Date.now();
  26. }