differenceInMilliseconds.mjs 1.0 KB

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