differenceInMinutes.cjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. exports.differenceInMinutes = differenceInMinutes;
  3. var _index = require("./_lib/getRoundingMethod.cjs");
  4. var _index2 = require("./constants.cjs");
  5. var _index3 = require("./differenceInMilliseconds.cjs");
  6. /**
  7. * The {@link differenceInMinutes} function options.
  8. */
  9. /**
  10. * @name differenceInMinutes
  11. * @category Minute Helpers
  12. * @summary Get the number of minutes between the given dates.
  13. *
  14. * @description
  15. * Get the signed number of full (rounded towards 0) minutes between the given dates.
  16. *
  17. * @param dateLeft - The later date
  18. * @param dateRight - The earlier date
  19. * @param options - An object with options.
  20. *
  21. * @returns The number of minutes
  22. *
  23. * @example
  24. * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
  25. * const result = differenceInMinutes(
  26. * new Date(2014, 6, 2, 12, 20, 0),
  27. * new Date(2014, 6, 2, 12, 7, 59)
  28. * )
  29. * //=> 12
  30. *
  31. * @example
  32. * // How many minutes are between 10:01:59 and 10:00:00
  33. * const result = differenceInMinutes(
  34. * new Date(2000, 0, 1, 10, 0, 0),
  35. * new Date(2000, 0, 1, 10, 1, 59)
  36. * )
  37. * //=> -1
  38. */
  39. function differenceInMinutes(dateLeft, dateRight, options) {
  40. const diff =
  41. (0, _index3.differenceInMilliseconds)(dateLeft, dateRight) /
  42. _index2.millisecondsInMinute;
  43. return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
  44. }