J
J
Johnick2019-11-03 20:00:14
PHP
Johnick, 2019-11-03 20:00:14

How to calculate working time?

Greetings.
What is the best way to calculate the end date of the time allotted for the employee to resolve the application, taking into account working days, working hours, breaks and short Friday?
Those. we pass to the function:

$startDate = '2019-10-31 10:20:00'; // текущее время
$plusTime = 8; // сколько времени дается на решение заявки
$unit = 1; // 1 - часы, 2 - дни
$workDayStart = '09:00'; // начало рабочего дня
$workDayEnd = '18:00'; // конец рабочего дня
$shortFriday = '16:30'; // конец рабочего дня в пятницу
$startPause = '12:00'; // начало перерыва
$endPause = '13:00'; // окончание перерыва
$tz = 'Europe/Moscow'; // в какой временной зоне производить расчет

echo addTimeToDate($startDate, $plusTime, $unit, $workDayStart, $workDayEnd, $shortFriday, $startPause, $endPause, $tz);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2019-11-03
@ThunderCat

Firstly, take out the settings separately, it is unlikely that everything works for you in discord, so $workDayStart and then can be moved to constants or static properties of the helper and not pass 10 parameters there. $unit can also be made an optional parameter with a default value, most likely it is in hours in most cases.
Next - convert hours / days to minutes and count, pure arithmetic, logic is almost zero.

R
Ramzesh Halifionakis, 2019-11-07
@ramiloremispum

Still, I would, nevertheless, translate all date and time values ​​into Timestamp. This will make it easier to count.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question