index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = differenceInHours;
  6. var _index = _interopRequireDefault(require("../differenceInMilliseconds/index.js"));
  7. var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. var MILLISECONDS_IN_HOUR = 3600000;
  10. /**
  11. * @name differenceInHours
  12. * @category Hour Helpers
  13. * @summary Get the number of hours between the given dates.
  14. *
  15. * @description
  16. * Get the number of hours between the given dates.
  17. *
  18. * ### v2.0.0 breaking changes:
  19. *
  20. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  21. *
  22. * @param {Date|Number} dateLeft - the later date
  23. * @param {Date|Number} dateRight - the earlier date
  24. * @returns {Number} the number of hours
  25. * @throws {TypeError} 2 arguments required
  26. *
  27. * @example
  28. * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
  29. * var result = differenceInHours(
  30. * new Date(2014, 6, 2, 19, 0),
  31. * new Date(2014, 6, 2, 6, 50)
  32. * )
  33. * //=> 12
  34. */
  35. function differenceInHours(dirtyDateLeft, dirtyDateRight) {
  36. (0, _index2.default)(2, arguments);
  37. var diff = (0, _index.default)(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR;
  38. return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
  39. }
  40. module.exports = exports.default;