differenceInHours.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. exports.differenceInHours = differenceInHours;
  3. var _index = require("./_lib/getRoundingMethod.js");
  4. var _index2 = require("./constants.js");
  5. var _index3 = require("./differenceInMilliseconds.js");
  6. /**
  7. * The {@link differenceInHours} function options.
  8. */
  9. /**
  10. * @name differenceInHours
  11. * @category Hour Helpers
  12. * @summary Get the number of hours between the given dates.
  13. *
  14. * @description
  15. * Get the number of hours 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 hours
  24. *
  25. * @example
  26. * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
  27. * const result = differenceInHours(
  28. * new Date(2014, 6, 2, 19, 0),
  29. * new Date(2014, 6, 2, 6, 50)
  30. * )
  31. * //=> 12
  32. */
  33. function differenceInHours(dateLeft, dateRight, options) {
  34. const diff =
  35. (0, _index3.differenceInMilliseconds)(dateLeft, dateRight) /
  36. _index2.millisecondsInHour;
  37. return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
  38. }