isThisWeek.js 1.2 KB

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