index.js 894 B

1234567891011121314151617181920212223242526272829
  1. var startOfQuarter = require('../start_of_quarter/index.js')
  2. /**
  3. * @category Quarter Helpers
  4. * @summary Are the given dates in the same year quarter?
  5. *
  6. * @description
  7. * Are the given dates in the same year quarter?
  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 quarter
  12. *
  13. * @example
  14. * // Are 1 January 2014 and 8 March 2014 in the same quarter?
  15. * var result = isSameQuarter(
  16. * new Date(2014, 0, 1),
  17. * new Date(2014, 2, 8)
  18. * )
  19. * //=> true
  20. */
  21. function isSameQuarter (dirtyDateLeft, dirtyDateRight) {
  22. var dateLeftStartOfQuarter = startOfQuarter(dirtyDateLeft)
  23. var dateRightStartOfQuarter = startOfQuarter(dirtyDateRight)
  24. return dateLeftStartOfQuarter.getTime() === dateRightStartOfQuarter.getTime()
  25. }
  26. module.exports = isSameQuarter