title: Check how many times a time range cross certain hour range
body: <p>We are building a visitor parking permit system, the permits have start and end datetime and are linked to a resident.</p>
  
  <p>An overnight is defined as completely crossing a hour range not just the midnight mark.  For example, if the parking permit crosses 10PM to 2:00AM or 2:00AM to 4:00AM then it's considered an overnight parking, this is customizable depending on how the system is configured.</p>
  
  <p>I'm really having some trouble designing and writing the logic for this, any help would be appreciated.  The follow diagram shows what I want to count.  Black horizontal line is the length of the parking permit and then red line is the hour range.</p>
  
  <p>The first parking permit uses 4 nights of parking and the second permit uses 6 nights.</p>
  
  <p>Please note that all the hour range are the same for every day of the week, i used paint so the red lines aren't all the same.</p>
  
  <p><img src="https://i.stack.imgur.com/pIgCg.png" alt="enter image description here"></p>