index.js 841 B

1234567891011121314151617181920212223242526272829
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Month Helpers
  4. * @summary Are the given dates in the same month?
  5. *
  6. * @description
  7. * Are the given dates in the same month?
  8. *
  9. * @param {Date|String|Number} dateLeft - the first date to check
  10. * @param {Date|String|Number} dateRight - the second date to check
  11. * @returns {Boolean} the dates are in the same month
  12. *
  13. * @example
  14. * // Are 2 September 2014 and 25 September 2014 in the same month?
  15. * var result = isSameMonth(
  16. * new Date(2014, 8, 2),
  17. * new Date(2014, 8, 25)
  18. * )
  19. * //=> true
  20. */
  21. function isSameMonth (dirtyDateLeft, dirtyDateRight) {
  22. var dateLeft = parse(dirtyDateLeft)
  23. var dateRight = parse(dirtyDateRight)
  24. return dateLeft.getFullYear() === dateRight.getFullYear() &&
  25. dateLeft.getMonth() === dateRight.getMonth()
  26. }
  27. module.exports = isSameMonth