index.js 1.5 KB

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