index.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isSameMonth
  5. * @category Month Helpers
  6. * @summary Are the given dates in the same month?
  7. *
  8. * @description
  9. * Are the given dates in the same month?
  10. *
  11. * ### v2.0.0 breaking changes:
  12. *
  13. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  14. *
  15. * @param {Date|Number} dateLeft - the first date to check
  16. * @param {Date|Number} dateRight - the second date to check
  17. * @returns {Boolean} the dates are in the same month
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // Are 2 September 2014 and 25 September 2014 in the same month?
  22. * var result = isSameMonth(new Date(2014, 8, 2), new Date(2014, 8, 25))
  23. * //=> true
  24. */
  25. export default function isSameMonth(dirtyDateLeft, dirtyDateRight) {
  26. requiredArgs(2, arguments);
  27. var dateLeft = toDate(dirtyDateLeft);
  28. var dateRight = toDate(dirtyDateRight);
  29. return dateLeft.getFullYear() === dateRight.getFullYear() && dateLeft.getMonth() === dateRight.getMonth();
  30. }