index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import isSameWeek from "../isSameWeek/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isThisWeek
  5. * @category Week Helpers
  6. * @summary Is the given date in the same week as the current date?
  7. * @pure false
  8. *
  9. * @description
  10. * Is the given date in the same week as the current date?
  11. *
  12. * > ⚠️ Please note that this function is not present in the FP submodule as
  13. * > it uses `Date.now()` internally hence impure and can't be safely curried.
  14. *
  15. * @param {Date|Number} date - the date to check
  16. * @param {Object} [options] - the object with options
  17. * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
  18. * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
  19. * @returns {Boolean} the date is in this week
  20. * @throws {TypeError} 1 argument required
  21. * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
  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. export default function isThisWeek(dirtyDate, options) {
  35. requiredArgs(1, arguments);
  36. return isSameWeek(dirtyDate, Date.now(), options);
  37. }