index.js 829 B

123456789101112131415161718192021222324252627
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isPast
  5. * @category Common Helpers
  6. * @summary Is the given date in the past?
  7. * @pure false
  8. *
  9. * @description
  10. * Is the given date in the past?
  11. *
  12. * > ⚠️ Please note that this function is not present in the FP submodule as
  13. * > it uses `Date.now()` internally hence impure and can't be safely curried.
  14. *
  15. * @param {Date|Number} date - the date to check
  16. * @returns {Boolean} the date is in the past
  17. * @throws {TypeError} 1 argument required
  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. export default function isPast(dirtyDate) {
  25. requiredArgs(1, arguments);
  26. return toDate(dirtyDate).getTime() < Date.now();
  27. }