需要写一个函数isValidDate($date), 条件如下:
function isValidDate($date)
{
//1. $date 是本周时 + time()要在$date前一天的18:00之前 = true
//2. $date 为下周时 + time()要在本周四下午六点后 = true
//3. 其余返回false. (注:一周从周一开始)
$orderTime = strtotime($date);
$now = time();
if(date('W',$orderTime) == date('W',$now) && (strtotime($date,$now) - $now) > 86400/4) //预订前一天的18:00,截止预订
{
return true;
}
if(date('W',$orderTime) == date('W',$now) + 1 && $now > strtotime('saturday 18:05 -2 day',$now)) //预订第二周,周四下午六点及之后
{
return true;
}
return false;
}
其中,我写第二个条件的时候,发现条件覆盖的时间好像有点问题,想看下各位的见解哈。
怎么感觉这是要强行给别人做面试题的呢?既然条理都能列 123 了,实现应该不是问题吧。。。