I'm trying to find time overlaps of a specific user, I think my logic would catch all over laps, but this catches only if start OR end is in between a time frame but nothing is found if both are start and end are in between some records time period!
$tempModel = clone $this; // clone model
$criteria->addCondition('
( t.user = :user AND (t.startDate >= :start AND t.startDate <= :end ))
OR
( t.user = :user AND (t.endDate >= :start AND t.endDate <= :end ))
');
$criteria->params = array(
':start' => date('Y-m-d', strtotime($tempModel->startDate)),
':end' => date('Y-m-d', strtotime($tempModel->endDate)),
':user ' => $tempModel->userID ,
);
if(!empty($tempModel->idUserTime)) // dont find updated record
$criteria->addCondition('t.idUserTime != ' . $tempModel->idUserTime);
$criteria->addCondition('t.active = 1'); // if this is an active user time
$hasRecord = Usertime::model()->findAll($criteria);
Where is the problem?
Two dates are overlapping, if at least one of each one's boundaies are between the other's boundaries: