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 (and year)?
  7. *
  8. * @description
  9. * Are the given dates in the same month (and year)?
  10. *
  11. * @param {Date|Number} dateLeft - the first date to check
  12. * @param {Date|Number} dateRight - the second date to check
  13. * @returns {Boolean} the dates are in the same month (and year)
  14. * @throws {TypeError} 2 arguments required
  15. *
  16. * @example
  17. * // Are 2 September 2014 and 25 September 2014 in the same month?
  18. * const result = isSameMonth(new Date(2014, 8, 2), new Date(2014, 8, 25))
  19. * //=> true
  20. *
  21. * @example
  22. * // Are 2 September 2014 and 25 September 2015 in the same month?
  23. * const result = isSameMonth(new Date(2014, 8, 2), new Date(2015, 8, 25))
  24. * //=> false
  25. */
  26. export default function isSameMonth(dirtyDateLeft, dirtyDateRight) {
  27. requiredArgs(2, arguments);
  28. var dateLeft = toDate(dirtyDateLeft);
  29. var dateRight = toDate(dirtyDateRight);
  30. return dateLeft.getFullYear() === dateRight.getFullYear() && dateLeft.getMonth() === dateRight.getMonth();
  31. }