src/TimeOverlapCalculator.php
public function calculateOverlap(
        TimeSlotInterface $baseTimeSlot,
        TimeSlotInterface $overlappingTimeSlot,
        $timeUnit = self::TIME_UNIT_SECOND
    ) {
        $overlapSize = 0;

        if ($this->isOverlap($baseTimeSlot, $overlappingTimeSlot)) {
            $overlapStart = ($baseTimeSlot->getStart() < $overlappingTimeSlot->getStart())
                ? $overlappingTimeSlot->getStart()
                : $baseTimeSlot->getStart();

            $overlapEnd = $baseTimeSlot->getEnd() > $overlappingTimeSlot->getEnd()
                ? $overlappingTimeSlot->getEnd()
                : $baseTimeSlot->getEnd();

            $overlapSize = $overlapEnd->getTimestamp() - $overlapStart->getTimestamp();
        }

        return $overlapSize / $timeUnit;
    }
public function calculateOverlap(
        TimeSlotInterface $baseTimeSlot,
        TimeSlotInterface $overlappingTimeSlot,
        $timeUnit = self::TIME_UNIT_SECOND
    ) {
        $overlapSize = 0;

        if ($this->isOverlap($baseTimeSlot, $overlappingTimeSlot)) {
            $overlapStart = ($baseTimeSlot->getStart() < $overlappingTimeSlot->getStart())
                ? $overlappingTimeSlot->getStart()
                : $baseTimeSlot->getStart();

            $overlapEnd = $baseTimeSlot->getEnd() > $overlappingTimeSlot->getEnd()
                ? $overlappingTimeSlot->getEnd()
                : $baseTimeSlot->getEnd();

            $overlapSize = $overlapEnd->getTimestamp() - $overlapStart->getTimestamp();
        }

        return $overlapSize / $timeUnit;
    }
Calculate size of overlap and convert into given time unit (seconds, minutes, hours, days)

@param TimeSlotInterface $baseTimeSlot
@param TimeSlotInterface $overlappingTimeSlot
@param int               $timeUnit            self::TIME_UNIT_SECOND by default

@return float