isThisWeek.cjs 1.1 KB

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