{"ast":null,"code":"import { getTimezoneOffsetInMilliseconds } from \"./_lib/getTimezoneOffsetInMilliseconds.mjs\";\nimport { millisecondsInDay } from \"./constants.mjs\";\nimport { toDate } from \"./toDate.mjs\";\n\n/**\n * @name getOverlappingDaysInIntervals\n * @category Interval Helpers\n * @summary Get the number of days that overlap in two time intervals\n *\n * @description\n * Get the number of days that overlap in two time intervals. It uses the time\n * between dates to calculate the number of days, rounding it up to include\n * partial days.\n *\n * Two equal 0-length intervals will result in 0. Two equal 1ms intervals will\n * result in 1.\n *\n * @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).\n *\n * @param intervalLeft - The first interval to compare.\n * @param intervalRight - The second interval to compare.\n *\n * @returns The number of days that overlap in two time intervals\n *\n * @example\n * // For overlapping time intervals adds 1 for each started overlapping day:\n * getOverlappingDaysInIntervals(\n *   { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },\n *   { start: new Date(2014, 0, 17), end: new Date(2014, 0, 21) }\n * )\n * //=> 3\n *\n * @example\n * // For non-overlapping time intervals returns 0:\n * getOverlappingDaysInIntervals(\n *   { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },\n *   { start: new Date(2014, 0, 21), end: new Date(2014, 0, 22) }\n * )\n * //=> 0\n */\n\nexport function getOverlappingDaysInIntervals(intervalLeft, intervalRight) {\n  const [leftStart, leftEnd] = [+toDate(intervalLeft.start), +toDate(intervalLeft.end)].sort((a, b) => a - b);\n  const [rightStart, rightEnd] = [+toDate(intervalRight.start), +toDate(intervalRight.end)].sort((a, b) => a - b);\n\n  // Prevent NaN result if intervals don't overlap at all.\n  const isOverlapping = leftStart < rightEnd && rightStart < leftEnd;\n  if (!isOverlapping) return 0;\n\n  // Remove the timezone offset to negate the DST effect on calculations.\n  const overlapLeft = rightStart < leftStart ? leftStart : rightStart;\n  const left = overlapLeft - getTimezoneOffsetInMilliseconds(overlapLeft);\n  const overlapRight = rightEnd > leftEnd ? leftEnd : rightEnd;\n  const right = overlapRight - getTimezoneOffsetInMilliseconds(overlapRight);\n\n  // Ceil the number to include partial days too.\n  return Math.ceil((right - left) / millisecondsInDay);\n}\n\n// Fallback for modularized imports:\nexport default getOverlappingDaysInIntervals;","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}