index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isThisWeek;
  6. var _index = _interopRequireDefault(require("../isSameWeek/index.js"));
  7. var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  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. * > ⚠️ Please note that this function is not present in the FP submodule as
  19. * > it uses `Date.now()` internally hence impure and can't be safely curried.
  20. *
  21. * ### v2.0.0 breaking changes:
  22. *
  23. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  24. *
  25. * @param {Date|Number} date - the date to check
  26. * @param {Object} [options] - the object with options
  27. * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
  28. * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
  29. * @returns {Boolean} the date is in this week
  30. * @throws {TypeError} 1 argument required
  31. * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
  32. *
  33. * @example
  34. * // If today is 25 September 2014, is 21 September 2014 in this week?
  35. * var result = isThisWeek(new Date(2014, 8, 21))
  36. * //=> true
  37. *
  38. * @example
  39. * // If today is 25 September 2014 and week starts with Monday
  40. * // is 21 September 2014 in this week?
  41. * var result = isThisWeek(new Date(2014, 8, 21), { weekStartsOn: 1 })
  42. * //=> false
  43. */
  44. function isThisWeek(dirtyDate, options) {
  45. (0, _index2.default)(1, arguments);
  46. return (0, _index.default)(dirtyDate, Date.now(), options);
  47. }
  48. module.exports = exports.default;