index.js 814 B

123456789101112131415161718192021222324252627
  1. var differenceInDays = require('../difference_in_days/index.js')
  2. /**
  3. * @category Week Helpers
  4. * @summary Get the number of full weeks between the given dates.
  5. *
  6. * @description
  7. * Get the number of full weeks 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 weeks
  12. *
  13. * @example
  14. * // How many full weeks are between 5 July 2014 and 20 July 2014?
  15. * var result = differenceInWeeks(
  16. * new Date(2014, 6, 20),
  17. * new Date(2014, 6, 5)
  18. * )
  19. * //=> 2
  20. */
  21. function differenceInWeeks (dirtyDateLeft, dirtyDateRight) {
  22. var diff = differenceInDays(dirtyDateLeft, dirtyDateRight) / 7
  23. return diff > 0 ? Math.floor(diff) : Math.ceil(diff)
  24. }
  25. module.exports = differenceInWeeks