index.js 930 B

1234567891011121314151617181920212223242526272829
  1. var differenceInMilliseconds = require('../difference_in_milliseconds/index.js')
  2. var MILLISECONDS_IN_MINUTE = 60000
  3. /**
  4. * @category Minute Helpers
  5. * @summary Get the number of minutes between the given dates.
  6. *
  7. * @description
  8. * Get the number of minutes between the given dates.
  9. *
  10. * @param {Date|String|Number} dateLeft - the later date
  11. * @param {Date|String|Number} dateRight - the earlier date
  12. * @returns {Number} the number of minutes
  13. *
  14. * @example
  15. * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
  16. * var result = differenceInMinutes(
  17. * new Date(2014, 6, 2, 12, 20, 0),
  18. * new Date(2014, 6, 2, 12, 7, 59)
  19. * )
  20. * //=> 12
  21. */
  22. function differenceInMinutes (dirtyDateLeft, dirtyDateRight) {
  23. var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_MINUTE
  24. return diff > 0 ? Math.floor(diff) : Math.ceil(diff)
  25. }
  26. module.exports = differenceInMinutes