Binary search algorithm for non-overlapping time spans and possible gaps
Flatter code is less arrow-shaped

In cases like this:


if( $max &lt; $min )
{
    return false;
}
else
{
    // more deeply nested conditions ...
}



When the if branch ends with a return statement,
you can eliminate the else branch,
making the code flatter and less arrow-shaped,
which often makes it easier to read:

if( $max &lt; $min )
{
    return false;
}

// more code ...


Fishy comparison

Although this is apparently valid PHP, comparing a date against a null value using the &gt; operator seems like a dirty hack:


else if( $date &gt; $finish )
{
    if( $finish == null )



I would reorganize the conditions in that piece of code:

if( $max &lt; $min )
{
    return false;
}

$mid = floor( $min + ( ( $max - $min ) / 2 ) );    
$node   = $this-&gt;nodes[ $mid ];
$start  = $node-&gt;getStart();
$finish = $node-&gt;getFinish();

if( $date &lt; $start )
{
    return $this-&gt;binarySearch( $date, $min, $mid - 1 );
}

if( $finish == null )
{
    return $node;
}

if( $date &gt; $finish )
{
    return $this-&gt;binarySearch( $date, $mid + 1, $max );
}

return $node;


Minor optimization

The find method recalculates the size of $this-&gt;nodes,
even though it cannot change after construction.
It would be better to calculate the size once,
at construction time.