index.js 1.5 KB

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