differenceInSeconds.cjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. exports.differenceInSeconds = differenceInSeconds;
  3. var _index = require("./_lib/getRoundingMethod.cjs");
  4. var _index2 = require("./differenceInMilliseconds.cjs");
  5. /**
  6. * The {@link differenceInSeconds} function options.
  7. */
  8. /**
  9. * @name differenceInSeconds
  10. * @category Second Helpers
  11. * @summary Get the number of seconds between the given dates.
  12. *
  13. * @description
  14. * Get the number of seconds between the given dates.
  15. *
  16. * @param laterDate - The later date
  17. * @param earlierDate - The earlier date
  18. * @param options - An object with options.
  19. *
  20. * @returns The number of seconds
  21. *
  22. * @example
  23. * // How many seconds are between
  24. * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
  25. * const result = differenceInSeconds(
  26. * new Date(2014, 6, 2, 12, 30, 20, 0),
  27. * new Date(2014, 6, 2, 12, 30, 7, 999)
  28. * )
  29. * //=> 12
  30. */
  31. function differenceInSeconds(laterDate, earlierDate, options) {
  32. const diff =
  33. (0, _index2.differenceInMilliseconds)(laterDate, earlierDate) / 1000;
  34. return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
  35. }