获取完成日期,给定开始日期和一周内的时间表

Get finish date, given start date and schedule in week

我在使用 PHP 获取课程完成日期时遇到问题,如下所示:

输入:

输出: 课程的完成日期(是 9/9/2019 以上输入)。

一节课就是一天。来自最终用户的输入字段:

抱歉我的英语不好。非常感谢!

试试这个代码,如果我理解正确的话))

<?
$startDay = '2019-09-25';
$aSchedule = array(1,2,4);
$iCntShed = count($aSchedule);
$iLessonsCnt = 8;
$iDWStartDay = date('w',strtotime($startDay));
$aDOWMap = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');

// first day according Schedule array and startDay
$aWeekDays = array_filter($aSchedule,function($iSDW) use ($iDWStartDay){
    return $iSDW>= $iDWStartDay;
});

// day according of week
$nextDate = date('Y-m-d',strtotime($startDay.' next '.$aDOWMap[end($aWeekDays)]));
$i = 0;

while (count($aWeekDays)<$iLessonsCnt) {
    $i = $i<$iCntShed ? $i : 0;
    $aWeekDays[] = $aSchedule[$i];
    $nextDate = date('Y-m-d',strtotime($nextDate.' next '.$aDOWMap[$aSchedule[$i++]]));
}

print_r($aWeekDays);

echo $nextDate;

正如我所见,它会在还有剩余课程时循环,并在星期一、星期二或星期五时减去。
循环输出日期后。

$start = "8/23/2019";
$days = ["Monday", "Tuesday", "Friday"];
$n = 8;

$d = strtotime($start);
while($n>0){
    //See if day is in days array
    if(in_array(date("l", $d), $days)){
        $n--;
    }
    $d += 86400; // go to next day
}

echo date("m/d/Y", $d-86400); //-86400 because  the loop adds one at the end.