differenceInMinutes.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. exports.differenceInMinutes = differenceInMinutes;
  3. var _index = require("./_lib/getRoundingMethod.js");
  4. var _index2 = require("./constants.js");
  5. var _index3 = require("./differenceInMilliseconds.js");
  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. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  18. *
  19. * @param dateLeft - The later date
  20. * @param dateRight - The earlier date
  21. * @param options - An object with options.
  22. *
  23. * @returns The number of minutes
  24. *
  25. * @example
  26. * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
  27. * const result = differenceInMinutes(
  28. * new Date(2014, 6, 2, 12, 20, 0),
  29. * new Date(2014, 6, 2, 12, 7, 59)
  30. * )
  31. * //=> 12
  32. *
  33. * @example
  34. * // How many minutes are between 10:01:59 and 10:00:00
  35. * const result = differenceInMinutes(
  36. * new Date(2000, 0, 1, 10, 0, 0),
  37. * new Date(2000, 0, 1, 10, 1, 59)
  38. * )
  39. * //=> -1
  40. */
  41. function differenceInMinutes(dateLeft, dateRight, options) {
  42. const diff =
  43. (0, _index3.differenceInMilliseconds)(dateLeft, dateRight) /
  44. _index2.millisecondsInMinute;
  45. return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
  46. }