index.js 849 B

123456789101112131415161718192021222324252627
  1. var differenceInMonths = require('../difference_in_months/index.js')
  2. /**
  3. * @category Quarter Helpers
  4. * @summary Get the number of full quarters between the given dates.
  5. *
  6. * @description
  7. * Get the number of full quarters between the given dates.
  8. *
  9. * @param {Date|String|Number} dateLeft - the later date
  10. * @param {Date|String|Number} dateRight - the earlier date
  11. * @returns {Number} the number of full quarters
  12. *
  13. * @example
  14. * // How many full quarters are between 31 December 2013 and 2 July 2014?
  15. * var result = differenceInQuarters(
  16. * new Date(2014, 6, 2),
  17. * new Date(2013, 11, 31)
  18. * )
  19. * //=> 2
  20. */
  21. function differenceInQuarters (dirtyDateLeft, dirtyDateRight) {
  22. var diff = differenceInMonths(dirtyDateLeft, dirtyDateRight) / 3
  23. return diff > 0 ? Math.floor(diff) : Math.ceil(diff)
  24. }
  25. module.exports = differenceInQuarters