title: Date intersection and space availability
body: <p>I am currently trying to check availability on a "space" within a date range, while this date range can be indefinitely long.
  The tables are as follows:</p>
  
  <p>Space:</p>
  
  <pre>
  id  available_spaces    name
  1   20                  Space 1
  2   40                  Space 2
  3   10                  Space 3
  </pre>
  
  <p>Booking (end_date can be null, this meaning endless booking):</p>
  
  <pre>
  id  space_id    start_date  end_date    spaces
  1   1           13/12-2017  null        9
  1   1           13/12-2017  13/12-2018  10
  </pre>
  
  <p>Then i would like to be able to make a search, an example could be:</p>
  
  <pre>
  from:   11/12-2016
  to:     null (again meaning endless)
  spaces: 2
  </pre>
  
  <p>This query should return the spaces: Space 2, Space 3, since those both have enough availability for that time interval.</p>
  
  <p>And by changing the amount of spaces needed in the search to 1 instead of 2 should yield the following:
  Search:</p>
  
  <pre>
  from:   11/12-2016
  to:     null (again meaning endless)
  spaces: 1
  </pre>
  
  <p>Space 1, Space 2, Space 3.
  The thing i find hard to solve is the variable amounts of spaces that can be available from month to month, and the ability to have endless bookings.</p>