0

我正在尝试查找特定用户的时间重叠,我认为我的逻辑会捕获所有圈数,但这仅在开始或结束在时间范围之间时才会捕获,但如果两者都在开始和结束之间则什么都找不到一些记录时间段!

 $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);

问题出在哪里?

4

1 回答 1

2

如果每个日期中的至少一个边界在另一个边界之间,则两个日期重叠:

...
WHERE some_other_conditions AND (
    date1.start BETWEEN date2.start AND date2.end OR
    date1.end   BETWEEN date2.start AND date2.end OR
    date2.start BETWEEN date1.start AND date1.end OR
    date2.end   BETWEEN date1.start AND date1.end
)
于 2013-10-12T12:24:09.133 回答