isThisWeek.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { constructFrom } from "./constructFrom.js";
  2. import { constructNow } from "./constructNow.js";
  3. import { isSameWeek } from "./isSameWeek.js";
  4. /**
  5. * The {@link isThisWeek} function options.
  6. */
  7. /**
  8. * @name isThisWeek
  9. * @category Week Helpers
  10. * @summary Is the given date in the same week as the current date?
  11. * @pure false
  12. *
  13. * @description
  14. * Is the given date in the same week as the current date?
  15. *
  16. * @param date - The date to check
  17. * @param options - The object with options
  18. *
  19. * @returns The date is in this week
  20. *
  21. * @example
  22. * // If today is 25 September 2014, is 21 September 2014 in this week?
  23. * const result = isThisWeek(new Date(2014, 8, 21))
  24. * //=> true
  25. *
  26. * @example
  27. * // If today is 25 September 2014 and week starts with Monday
  28. * // is 21 September 2014 in this week?
  29. * const result = isThisWeek(new Date(2014, 8, 21), { weekStartsOn: 1 })
  30. * //=> false
  31. */
  32. export function isThisWeek(date, options) {
  33. return isSameWeek(
  34. constructFrom(options?.in || date, date),
  35. constructNow(options?.in || date),
  36. options,
  37. );
  38. }
  39. // Fallback for modularized imports:
  40. export default isThisWeek;