differenceInMinutes.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
  2. import { millisecondsInMinute } from "./constants.js";
  3. import { differenceInMilliseconds } from "./differenceInMilliseconds.js";
  4. /**
  5. * The {@link differenceInMinutes} function options.
  6. */
  7. /**
  8. * @name differenceInMinutes
  9. * @category Minute Helpers
  10. * @summary Get the number of minutes between the given dates.
  11. *
  12. * @description
  13. * Get the signed number of full (rounded towards 0) minutes between the given dates.
  14. *
  15. * @param dateLeft - The later date
  16. * @param dateRight - The earlier date
  17. * @param options - An object with options.
  18. *
  19. * @returns The number of minutes
  20. *
  21. * @example
  22. * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
  23. * const 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 between 10:01:59 and 10:00:00
  31. * const 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 function differenceInMinutes(dateLeft, dateRight, options) {
  38. const diff =
  39. differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
  40. return getRoundingMethod(options?.roundingMethod)(diff);
  41. }
  42. // Fallback for modularized imports:
  43. export default differenceInMinutes;