differenceInSeconds.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. exports.differenceInSeconds = differenceInSeconds;
  3. var _index = require("./_lib/getRoundingMethod.js");
  4. var _index2 = require("./differenceInMilliseconds.js");
  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. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  17. *
  18. * @param dateLeft - The later date
  19. * @param dateRight - The earlier date
  20. * @param options - An object with options.
  21. *
  22. * @returns The number of seconds
  23. *
  24. * @example
  25. * // How many seconds are between
  26. * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
  27. * const result = differenceInSeconds(
  28. * new Date(2014, 6, 2, 12, 30, 20, 0),
  29. * new Date(2014, 6, 2, 12, 30, 7, 999)
  30. * )
  31. * //=> 12
  32. */
  33. function differenceInSeconds(dateLeft, dateRight, options) {
  34. const diff =
  35. (0, _index2.differenceInMilliseconds)(dateLeft, dateRight) / 1000;
  36. return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
  37. }