index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = differenceInSeconds;
  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. /**
  10. * @name differenceInSeconds
  11. * @category Second Helpers
  12. * @summary Get the number of seconds between the given dates.
  13. *
  14. * @description
  15. * Get the number of seconds 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 seconds
  24. * @throws {TypeError} 2 arguments required
  25. *
  26. * @example
  27. * // How many seconds are between
  28. * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
  29. * const result = differenceInSeconds(
  30. * new Date(2014, 6, 2, 12, 30, 20, 0),
  31. * new Date(2014, 6, 2, 12, 30, 7, 999)
  32. * )
  33. * //=> 12
  34. */
  35. function differenceInSeconds(dirtyDateLeft, dirtyDateRight) {
  36. (0, _index2.default)(2, arguments);
  37. var diff = (0, _index.default)(dirtyDateLeft, dirtyDateRight) / 1000;
  38. return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
  39. }
  40. module.exports = exports.default;