differenceInMilliseconds.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. exports.differenceInMilliseconds = differenceInMilliseconds;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name differenceInMilliseconds
  6. * @category Millisecond Helpers
  7. * @summary Get the number of milliseconds between the given dates.
  8. *
  9. * @description
  10. * Get the number of milliseconds between the given dates.
  11. *
  12. * @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).
  13. *
  14. * @param dateLeft - The later date
  15. * @param dateRight - The earlier date
  16. *
  17. * @returns The number of milliseconds
  18. *
  19. * @example
  20. * // How many milliseconds are between
  21. * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
  22. * const result = differenceInMilliseconds(
  23. * new Date(2014, 6, 2, 12, 30, 21, 700),
  24. * new Date(2014, 6, 2, 12, 30, 20, 600)
  25. * )
  26. * //=> 1100
  27. */
  28. function differenceInMilliseconds(dateLeft, dateRight) {
  29. return +(0, _index.toDate)(dateLeft) - +(0, _index.toDate)(dateRight);
  30. }