index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = differenceInMinutes;
  7. var _index = require("../constants/index.js");
  8. var _index2 = _interopRequireDefault(require("../differenceInMilliseconds/index.js"));
  9. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. var _index4 = require("../_lib/roundingMethods/index.js");
  11. /**
  12. * @name differenceInMinutes
  13. * @category Minute Helpers
  14. * @summary Get the number of minutes between the given dates.
  15. *
  16. * @description
  17. * Get the signed number of full (rounded towards 0) minutes between the given dates.
  18. *
  19. * @param {Date|Number} dateLeft - the later date
  20. * @param {Date|Number} dateRight - the earlier date
  21. * @param {Object} [options] - an object with options.
  22. * @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`)
  23. * @returns {Number} the number of minutes
  24. * @throws {TypeError} 2 arguments required
  25. *
  26. * @example
  27. * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
  28. * const result = differenceInMinutes(
  29. * new Date(2014, 6, 2, 12, 20, 0),
  30. * new Date(2014, 6, 2, 12, 7, 59)
  31. * )
  32. * //=> 12
  33. *
  34. * @example
  35. * // How many minutes are between 10:01:59 and 10:00:00
  36. * const result = differenceInMinutes(
  37. * new Date(2000, 0, 1, 10, 0, 0),
  38. * new Date(2000, 0, 1, 10, 1, 59)
  39. * )
  40. * //=> -1
  41. */
  42. function differenceInMinutes(dateLeft, dateRight, options) {
  43. (0, _index3.default)(2, arguments);
  44. var diff = (0, _index2.default)(dateLeft, dateRight) / _index.millisecondsInMinute;
  45. return (0, _index4.getRoundingMethod)(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
  46. }
  47. module.exports = exports.default;