php故障方案,根据给定的日期和持续时间计算开始/结束日期

时间:2019-01-23 04:32:32

标签: php datetime lumen php-carbon

我正在为我的客户开发项目管理应用程序。要求是创建任务并分配给给定的员工。如果给出了结束日期,我需要计算开始日期,反之亦然。我希望我已经用注释清楚地解释了我的代码。

问题在于,我得到的回复有时只是不正确的。我找不到日期错误的情况。您能检查我的代码并让我知道是否可以找到错误输入日期的情况,以便我解决。

我被授予对服务器的访问权限,因为此代码正在通过调度程序执行,并且我无权访问日志文件。

请帮助我解决问题。非常感谢您的帮助。

/**
    *** PARAMETERS ***
    * $givenDate - Carbon object
    * $totalDays - no. of days required/assigned for the task
    * $direction - calculate the date either forward or backward from the given date

    *** VARIABLES ***
    * $taskdays
        -> Array of dates in which tasks already assigned to the particular employee
    * $leaves
        -> Array of dates in which tasks the particular employee has applied for leave & approved
    * $holidays
        -> Array of dates - planned holidays for a particular branch of a company
        -> Since branches of the company are located in different countries, applicable holidays are also set based on the country of the branch location.
    * $weekends
        -> Array of days(eg., $days=array('Saturday', 'Sunday')) - weekends for a particular branch of a company.
        -> Since branches of the company are located in different countries, weekends are followed based on the country of the branch location.
        -> eg., Qatar(Friday & Saturday), India(Saturday & Sunday), Bangladesh(Sunday Only)
**/

private function calculateStartEndDates($givenDate, $totalDays=1, $direction='forward') {
    $taskdays = $this->getTaskAssignedDays($employeeId);
    $leaves = $this->getApprovedLeaveDays($employeeId);
    $holidays = $this->getHolidays($companyBranchId);
    $weekends = $this->getWeekends($companyBranchId);

    while($totalDays > 0) {
        if($direction == 'backward') {
            $givenDate = $givenDate->subDays(1);
        } else {
            $givenDate = $givenDate->addDays(1);
        }
        $currentDate = $givenDate->format('Y-m-d');
        if(!in_array($currentDate, $taskdays) && !in_array($currentDate, $leaves) && !in_array($currentDate, $holidays) && !in_array($givenDate->format('l'), $weekends)) {
            $totalDays--;
        }
    }
    return $givenDate;
}

0 个答案:

没有答案