index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getWeeksInMonth;
  6. var _index = _interopRequireDefault(require("../differenceInCalendarWeeks/index.js"));
  7. var _index2 = _interopRequireDefault(require("../lastDayOfMonth/index.js"));
  8. var _index3 = _interopRequireDefault(require("../startOfMonth/index.js"));
  9. var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. /**
  12. * @name getWeeksInMonth
  13. * @category Week Helpers
  14. * @summary Get the number of calendar weeks a month spans.
  15. *
  16. * @description
  17. * Get the number of calendar weeks the month in the given date spans.
  18. *
  19. * ### v2.0.0 breaking changes:
  20. *
  21. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  22. *
  23. * @param {Date|Number} date - the given date
  24. * @param {Object} [options] - an object with options.
  25. * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
  26. * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
  27. * @returns {Number} the number of calendar weeks
  28. * @throws {TypeError} 2 arguments required
  29. * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
  30. *
  31. * @example
  32. * // How many calendar weeks does February 2015 span?
  33. * const result = getWeeksInMonth(new Date(2015, 1, 8))
  34. * //=> 4
  35. *
  36. * @example
  37. * // If the week starts on Monday,
  38. * // how many calendar weeks does July 2017 span?
  39. * const result = getWeeksInMonth(new Date(2017, 6, 5), { weekStartsOn: 1 })
  40. * //=> 6
  41. */
  42. function getWeeksInMonth(date, options) {
  43. (0, _index4.default)(1, arguments);
  44. return (0, _index.default)((0, _index2.default)(date), (0, _index3.default)(date), options) + 1;
  45. }
  46. module.exports = exports.default;