index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = differenceInMinutes;
  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_MINUTE = 60000;
  10. /**
  11. * @name differenceInMinutes
  12. * @category Minute Helpers
  13. * @summary Get the number of minutes between the given dates.
  14. *
  15. * @description
  16. * Get the signed number of full (rounded towards 0) minutes 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 minutes
  25. * @throws {TypeError} 2 arguments required
  26. *
  27. * @example
  28. * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
  29. * var result = differenceInMinutes(
  30. * new Date(2014, 6, 2, 12, 20, 0),
  31. * new Date(2014, 6, 2, 12, 7, 59)
  32. * )
  33. * //=> 12
  34. *
  35. * @example
  36. * // How many minutes are from 10:01:59 to 10:00:00
  37. * var result = differenceInMinutes(
  38. * new Date(2000, 0, 1, 10, 0, 0),
  39. * new Date(2000, 0, 1, 10, 1, 59)
  40. * )
  41. * //=> -1
  42. */
  43. function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
  44. (0, _index2.default)(2, arguments);
  45. var diff = (0, _index.default)(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_MINUTE;
  46. return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
  47. }
  48. module.exports = exports.default;