【发布时间】:2017-12-21 10:29:44
【问题描述】:
我有工作人员的时间清单。我需要了解是否有员工单独工作,以及他们一天单独工作了多少分钟
| staff| start | end |
|:--- |:--- |:--- |
| 1 | 11:05 | 20:00 |
| 2 | 11:00 | 17:00 |
| 3 | 19:00 | 03:00 |
| 4 | 13:00 | 20:00 |
| 5 | 19:00 | 03:00 |
对于Andreas' help,下面是获取第一个和最后一个单独工作的人的代码,但它并不完全正确。因为如果有 3 个不同时间的人单独工作,就会出现问题。 https://3v4l.org/6OmjO
$staff = array(1,2,3,4,5);
$start = array("11:05", "11:00", "19:00", "13:00", "19:00");
$end = array("20:00", "17:00", "03:00", "20:00", "03:05");
array_multisort($start, $end, $staff);
$aloneStart = (strtotime($start[1]) - strtotime($start[0])) / 60; // first and second items are the ones that may be working alone at start
$aloneEnd = (strtotime($end[count($end) - 1]) - strtotime($end[count($end) - 2])) / 60; // last and second to last are the ones that may be working alone at end
if ($aloneStart > 0)
{
$staffAloneStart = $staff[0]; //must be the first who worked alone
echo "minutes alone at start: " . $aloneStart . " and it was " . $staffAloneStart . "\n";
}
if ($aloneEnd > 0)
{
$staffAloneEnd = $staff[count($end) - 1]; // must be the last to end that worked alone
echo "minutes alone at end: " . $aloneEnd . " and it was " . $staffAloneEnd . "\n";
}
$aloneTime = intval($aloneStart) + intval($aloneEnd);
echo "total time alone " . $aloneTime;
使用以下数组,您会看到第一个用户的分钟数需要超过 5 分钟,因为他在晚上更多地独自工作。
$staff = array(1, 2, 3, 4, 5);
$start = array("11:05", "11:10", "19:00", "13:00", "19:00");
$end = array("20:00", "17:00", "03:00", "16:00", "03:00");
【问题讨论】:
-
@mickmackusa 添加日期不是问题,是我很困惑的计算。由于我们必须跟踪所有员工,这些员工可能在轮班期间单独工作,并计算他/她单独工作的分钟数。..
-
@mickmackusa 我理解他的两个问题的方式,输出应该是告诉他谁已经单独和多久了。你如何呈现它可能并不那么重要,因为他似乎无论如何都能将你的输出更改为他想要的。我可能错了,但这就是我对 Basit 的理解。他也有很多关于 PHP 的问题和答案,所以我认为他可以处理你给他的任何输出。
-
热切期待……
标签: php datetime time schedule calculation