getOverlappingDaysInIntervals.d.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import type { Interval } from "./types.js";
  2. /**
  3. * @name getOverlappingDaysInIntervals
  4. * @category Interval Helpers
  5. * @summary Get the number of days that overlap in two time intervals
  6. *
  7. * @description
  8. * Get the number of days that overlap in two time intervals. It uses the time
  9. * between dates to calculate the number of days, rounding it up to include
  10. * partial days.
  11. *
  12. * Two equal 0-length intervals will result in 0. Two equal 1ms intervals will
  13. * result in 1.
  14. *
  15. * @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).
  16. *
  17. * @param intervalLeft - The first interval to compare.
  18. * @param intervalRight - The second interval to compare.
  19. *
  20. * @returns The number of days that overlap in two time intervals
  21. *
  22. * @example
  23. * // For overlapping time intervals adds 1 for each started overlapping day:
  24. * getOverlappingDaysInIntervals(
  25. * { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
  26. * { start: new Date(2014, 0, 17), end: new Date(2014, 0, 21) }
  27. * )
  28. * //=> 3
  29. *
  30. * @example
  31. * // For non-overlapping time intervals returns 0:
  32. * getOverlappingDaysInIntervals(
  33. * { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
  34. * { start: new Date(2014, 0, 21), end: new Date(2014, 0, 22) }
  35. * )
  36. * //=> 0
  37. */
  38. export declare function getOverlappingDaysInIntervals<DateType extends Date>(
  39. intervalLeft: Interval<DateType>,
  40. intervalRight: Interval<DateType>,
  41. ): number;