index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = isSameMonth;
  7. var _index = _interopRequireDefault(require("../toDate/index.js"));
  8. var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  9. /**
  10. * @name isSameMonth
  11. * @category Month Helpers
  12. * @summary Are the given dates in the same month (and year)?
  13. *
  14. * @description
  15. * Are the given dates in the same month (and year)?
  16. *
  17. * @param {Date|Number} dateLeft - the first date to check
  18. * @param {Date|Number} dateRight - the second date to check
  19. * @returns {Boolean} the dates are in the same month (and year)
  20. * @throws {TypeError} 2 arguments required
  21. *
  22. * @example
  23. * // Are 2 September 2014 and 25 September 2014 in the same month?
  24. * const result = isSameMonth(new Date(2014, 8, 2), new Date(2014, 8, 25))
  25. * //=> true
  26. *
  27. * @example
  28. * // Are 2 September 2014 and 25 September 2015 in the same month?
  29. * const result = isSameMonth(new Date(2014, 8, 2), new Date(2015, 8, 25))
  30. * //=> false
  31. */
  32. function isSameMonth(dirtyDateLeft, dirtyDateRight) {
  33. (0, _index2.default)(2, arguments);
  34. var dateLeft = (0, _index.default)(dirtyDateLeft);
  35. var dateRight = (0, _index.default)(dirtyDateRight);
  36. return dateLeft.getFullYear() === dateRight.getFullYear() && dateLeft.getMonth() === dateRight.getMonth();
  37. }
  38. module.exports = exports.default;