title: Finding overlap of sessions
body: <p>I have an arbitrary number of sessions with start and end timestamps</p>
  
  <p>Some of these sessions overlap.  Multiple sessions could overlap at the same time.</p>
  
  <p>I am trying to find an algorithm that can detect the number of seconds of overlap.  IE given 3 sessions like</p>
  
  <pre><code>-ID-|-start-|-end-|
  --1-|-----4-|--10-|
  --2-|-----5-|--12-|
  --3-|-----8-|--13-|
  </code></pre>
  
  <p>have it return a number that is the number of seconds that the sessions overlap.</p>
  
  <p>I have read about <a href="https://en.wikipedia.org/wiki/Interval_tree" rel="nofollow noreferrer">interval trees</a> and looked at python packages like <a href="https://www.google.com/search?q=interval%20tree%20python&amp;oq=interval%20tree%20python&amp;aqs=chrome..69i57j0l3.4061j0j1&amp;sourceid=chrome&amp;ie=UTF-8" rel="nofollow noreferrer">this one</a>.</p>
  
  <p>However, I am unsure how to get the number of seconds of overlap for a given set of records.  Do you know of an algorithm or package?  Python preferred but open to other languages and I can reimplement.</p>