index.js 850 B

123456789101112131415161718192021222324252627
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isFuture
  5. * @category Common Helpers
  6. * @summary Is the given date in the future?
  7. * @pure false
  8. *
  9. * @description
  10. * Is the given date in the future?
  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 future
  17. * @throws {TypeError} 1 argument required
  18. *
  19. * @example
  20. * // If today is 6 October 2014, is 31 December 2014 in the future?
  21. * const result = isFuture(new Date(2014, 11, 31))
  22. * //=> true
  23. */
  24. export default function isFuture(dirtyDate) {
  25. requiredArgs(1, arguments);
  26. return toDate(dirtyDate).getTime() > Date.now();
  27. }