diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 8ff2f226..511dc5ca 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -213,23 +213,25 @@ function admin_shifts() $shift_start = $shift_end; } while ($shift_end < $end); } elseif ($mode == 'variable') { + // Fehlende Minutenangaben ergänzen array_walk($change_hours, function (&$value) { if (!preg_match('/^\d{1,2}:\d{2}$/', $value)) { $value .= ':00'; } }); + // Chronologisch absteigend sortieren usort($change_hours, function ($a, $b) { return str_replace(':', '', $a) > str_replace(':', '', $b) ? -1 : 1; }); + // Start-Tag $day = parse_date('Y-m-d H:i', date('Y-m-d', $start) . ' 00:00'); + $change_index = 0; // Ersten/nächsten passenden Schichtwechsel suchen foreach ($change_hours as $i => $change_time) { - $change_time = explode(':', $change_time); - $change_hour = $change_time[0]; - $change_minute = $change_time[1]; + list($change_hour, $change_minute) = explode(':', $change_time); $shift_end = $day + $change_hour * 60 * 60 + $change_minute * 60; if ($start < $shift_end) { @@ -247,10 +249,7 @@ function admin_shifts() do { $day = parse_date('Y-m-d H:i', date('Y-m-d', $shift_start) . ' 00:00'); - $change_time = $change_hours[$change_index]; - $change_time = explode(':', $change_time); - $change_hour = $change_time[0]; - $change_minute = $change_time[1]; + list($change_hour, $change_minute) = explode(':', $change_hours[$change_index]); $shift_end = $day + $change_hour * 60 * 60 + $change_minute * 60; @@ -259,6 +258,9 @@ function admin_shifts() } if ($shift_start >= $shift_end) { $shift_end += 24 * 60 * 60; + if ($shift_end > $end) { + $shift_end = $end; + } } $shifts[] = [