蓝山帝景
我写了下面的函数来实现它。并且它在初始测试中运行良好。$Day_Config = array( 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday' );$Week_Config = array( 1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth', ); function weekOfMonth($date) { #Get the first day of the month. $firstOfMonth = strtotime(date("Y-m-01", strtotime($date))); #Apply formula. return intval(date("W", strtotime($date))) - intval(date("W", $firstOfMonth)) + 1; } function getDateFromText ($year,$month,$week,$day) { global $Day_Config; global $Week_Config; $txtFormat = $Week_Config["$week"]." ".strtolower($Day_Config["$day"])." of ".date("F", mktime(0, 0, 0, $month, 10))." ".$year; $DateFromTtxt = date('Y-m-d', strtotime("$txtFormat")); return $DateFromTtxt; }function getNextRuntime ($day,$week,$month,$time) { #Get Current Day Details $Year = date("Y"); $thisMonth = date("n"); $thisWeek = weekOfMonth(date("Y-m-d")); $thisDay = date('N'); #Get Received Data From DB $Days = explode(",",$day); $Weeks = explode(",",$week); $Months = explode(",",$month); #Loop Through Months foreach ($Months as $Value_Month){ if($Value_Month >= $thisMonth){ #Loop Through Weeks foreach ($Weeks as $Value_Week){ if($Value_Month == $thisMonth){ if($Value_Week >= $thisWeek){ #Loop Through Days foreach ($Days as $Value_Day){ if($Value_Month == $thisMonth && $Value_Week == $thisWeek){ if($Value_Day >= $thisDay){ if($Value_Day == $thisDay && $time > date('H:i:00')){ return getDateFromText($Year, $Value_Month, $Value_Week, $Value_Day); } elseif ($Value_Day != $thisDay) { $Result = getDateFromText($Year, $Value_Month, $Value_Week, $Value_Day); $Result_Month = date('n', strtotime($Result)); if($Result_Month == $Value_Month){ return $Result; } } } } else { $Result = getDateFromText($Year, $Value_Month, $Value_Week, $Value_Day); $Result_Month = date('n', strtotime($Result)); if($Result_Month == $Value_Month){ return $Result; } else { break; } } } } } else { foreach ($Days as $Value_Day){ $Result = getDateFromText($Year, $Value_Month, $Value_Week, $Value_Day); $Result_Month = date('n', strtotime($Result)); if($Result_Month == $Value_Month){ return $Result; } else { break; } } } } } } #Select Next Year If Current Year Not Provided Any Date ++$Year; foreach ($Months as $Value_Month){ foreach ($Weeks as $Value_Week){ foreach ($Days as $Value_Day){ $Result = getDateFromText($Year, $Value_Month, $Value_Week, $Value_Day); $Result_Month = date('n', strtotime($Result)); if($Result_Month == $Value_Month){ return $Result; } else { break; } } } } return false; }#Testing Functions$day = '2,5,7';$week = '2,5';$month = '9,10';$time = '10:00:00';echo getNextRuntime ($day,$week,$month,$time)#OutputIf you are running it on 13th September 2020 before 10:00 AM, then the output will be as below```2020-09-13```