Php 根据票据创建日期定义到期日期
我正在构建SLA KPI。 SLA基于票证类型和优先级,每种类型和优先级都有一个到期日 问题是,我只在创建了字段,没有这个截止日期,所以我需要计算它,如上所述,使用参数优先级和类型来定义正确的日期 但我真正的问题是,如何在PHP上计算它,考虑到工作日和工作时间,周一到周五,8:00到18:00 比如说 票证创建时间为2019-06-04 08:00:00,截止时间为16小时。Php 根据票据创建日期定义到期日期,php,deadlines,Php,Deadlines,我正在构建SLA KPI。 SLA基于票证类型和优先级,每种类型和优先级都有一个到期日 问题是,我只在创建了字段,没有这个截止日期,所以我需要计算它,如上所述,使用参数优先级和类型来定义正确的日期 但我真正的问题是,如何在PHP上计算它,考虑到工作日和工作时间,周一到周五,8:00到18:00 比如说 票证创建时间为2019-06-04 08:00:00,截止时间为16小时。 因此,在挖掘了大量的答案之后,我找到了一个解决问题的函数 function addRollover($given
因此,在挖掘了大量的答案之后,我找到了一个解决问题的函数
function addRollover($givenDate, $addtime, $dayStart, $dayEnd, $weekDaysOnly) {
//Break the working day start and end times into hours, minuets
$dayStart = explode(',', $dayStart);
$dayEnd = explode(',', $dayEnd);
//Create required datetime objects and hours interval
$datetime = new DateTime($givenDate);
$endofday = clone $datetime;
$endofday->setTime($dayEnd[0], $dayEnd[1]); //set end of working day time
$interval = 'PT'.$addtime.'H';
//Add hours onto initial given date
$datetime->add(new DateInterval($interval));
//if initial date + hours is after the end of working day
if($datetime > $endofday)
{
//get the difference between the initial date + interval and the end of working day in seconds
$seconds = $datetime->getTimestamp()- $endofday->getTimestamp();
//Loop to next day
while(true)
{
$endofday->add(new DateInterval('PT24H'));//Loop to next day by adding 24hrs
$nextDay = $endofday->setTime($dayStart[0], $dayStart[1]);//Set day to working day start time
//If the next day is on a weekend and the week day only param is true continue to add days
if(in_array($nextDay->format('l'), array('Sunday','Saturday')) && $weekDaysOnly)
{
continue;
}
else //If not a weekend
{
$tmpDate = clone $nextDay;
$tmpDate->setTime($dayEnd[0], $dayEnd[1]);//clone the next day and set time to working day end time
$nextDay->add(new DateInterval('PT'.$seconds.'S')); //add the seconds onto the next day
//if the next day time is later than the end of the working day continue loop
if($nextDay > $tmpDate)
{
$seconds = $nextDay->getTimestamp()-$tmpDate->getTimestamp();
$endofday = clone $tmpDate;
$endofday->setTime($dayStart[0], $dayStart[1]);
}
else //else return the new date.
{
return $endofday;
}
}
}
}
return $datetime;
}
谢谢大家。,你说得对,我忘了提到午餐时间了。谢谢,我会读它的可能副本。不,不是,我读过那篇文章,但我也需要计算时间,我不知道怎么做。我来这里寻求帮助,至少是想知道在哪里寻找正确的道路。谢谢