index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = isThisWeek;
  7. var _index = _interopRequireDefault(require("../isSameWeek/index.js"));
  8. var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  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. * @param {Date|Number} date - the date to check
  22. * @param {Object} [options] - the object with options
  23. * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
  24. * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
  25. * @returns {Boolean} the date is in this week
  26. * @throws {TypeError} 1 argument required
  27. * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
  28. *
  29. * @example
  30. * // If today is 25 September 2014, is 21 September 2014 in this week?
  31. * const result = isThisWeek(new Date(2014, 8, 21))
  32. * //=> true
  33. *
  34. * @example
  35. * // If today is 25 September 2014 and week starts with Monday
  36. * // is 21 September 2014 in this week?
  37. * const result = isThisWeek(new Date(2014, 8, 21), { weekStartsOn: 1 })
  38. * //=> false
  39. */
  40. function isThisWeek(dirtyDate, options) {
  41. (0, _index2.default)(1, arguments);
  42. return (0, _index.default)(dirtyDate, Date.now(), options);
  43. }
  44. module.exports = exports.default;