isToday.js 821 B

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