index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import differenceInMilliseconds from "../differenceInMilliseconds/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. var MILLISECONDS_IN_MINUTE = 60000;
  4. /**
  5. * @name differenceInMinutes
  6. * @category Minute Helpers
  7. * @summary Get the number of minutes between the given dates.
  8. *
  9. * @description
  10. * Get the signed number of full (rounded towards 0) minutes between the given dates.
  11. *
  12. * ### v2.0.0 breaking changes:
  13. *
  14. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  15. *
  16. * @param {Date|Number} dateLeft - the later date
  17. * @param {Date|Number} dateRight - the earlier date
  18. * @returns {Number} the number of minutes
  19. * @throws {TypeError} 2 arguments required
  20. *
  21. * @example
  22. * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
  23. * var result = differenceInMinutes(
  24. * new Date(2014, 6, 2, 12, 20, 0),
  25. * new Date(2014, 6, 2, 12, 7, 59)
  26. * )
  27. * //=> 12
  28. *
  29. * @example
  30. * // How many minutes are from 10:01:59 to 10:00:00
  31. * var result = differenceInMinutes(
  32. * new Date(2000, 0, 1, 10, 0, 0),
  33. * new Date(2000, 0, 1, 10, 1, 59)
  34. * )
  35. * //=> -1
  36. */
  37. export default function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
  38. requiredArgs(2, arguments);
  39. var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_MINUTE;
  40. return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
  41. }