isToday.mjs 789 B

1234567891011121314151617181920212223242526272829
  1. import { constructNow } from "./constructNow.mjs";
  2. import { isSameDay } from "./isSameDay.mjs";
  3. /**
  4. * @name isToday
  5. * @category Day Helpers
  6. * @summary Is the given date today?
  7. * @pure false
  8. *
  9. * @description
  10. * Is the given date today?
  11. *
  12. * @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).
  13. *
  14. * @param date - The date to check
  15. *
  16. * @returns The date is today
  17. *
  18. * @example
  19. * // If today is 6 October 2014, is 6 October 14:00:00 today?
  20. * const result = isToday(new Date(2014, 9, 6, 14, 0))
  21. * //=> true
  22. */
  23. export function isToday(date) {
  24. return isSameDay(date, constructNow(date));
  25. }
  26. // Fallback for modularized imports:
  27. export default isToday;