isThisWeek.mjs 1.2 KB

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