我的数据库保存日期,开始和结束变量。在我的代码我抢的开始和他们作为用户选择它们,并将它们转换为时间戳像这样(所有foreach循环内)..验证时间戳与PHP重叠
$selectionDate = strtotime($timeQry['date']);
$startTimes[] = strtotime($timeQry['start'],$selectionDate);
$endTimes[] = strtotime($timeQry['end'],$selectionDate);
这给了我正确的开始和结束时间的时间戳。然后,我有一个逻辑语句来验证一下,看看是否有任何选定时间的重叠....
if(($startTimes[1] < $startTimes[0]) && ($endTimes[1] > $startTimes[0]) ||
($startTimes[1] > $startTimes[0]) && ($startTimes[1] < $endTimes[0]))
{
echo "overlap"
}
这如果要是以后结束时间的一个深夜12时正常工作的大部分时间,但是(比如说上午02:00),那么时间戳将小于开始时间,因为代码使用预订开始的日期。这会导致逻辑失败并错过重叠。
我曾经想过做:
if(($endTimes[$k] >= $selectionDate))
{
$endTimes[] = strtotime($timeQry['end'],$newDate+ 1253574000);
}
else
{
$endTimes[] = strtotime($timeQry['end'],$selectionDate);
}
//...run same logic query
这将创建一个新的日期是一天之后。但我认为这不是正确的做法。如果有人能帮助我,我将非常感激。这让我挠了一下我的头!非常感谢
我意识到设计应该会更好。我当时对这种类型的新东西很陌生。我可能会在将来改变它,但现在我需要首先对这个想法进行排序 – whamo 2009-09-18 16:37:42