-
-
Save mbriceno/af2c9898f36de9e837555eb63165267d to your computer and use it in GitHub Desktop.
Algoritmo en PHP Dados los conceptos que indican hora de inicio y hora de fin de las horas ordinarias (HO), horas extras (HED) y horas extras nocturnas (HEN), se requiere determinar el total de horas ordinarias (HO), horas extras (HED) y horas extras nocturnas (HEN) laboradas por un empleado de acuerdo con las marcaciones de entrada y salida.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function classifyAttendances($concepts, $attendanceIn, $attendanceOut) { | |
$concepts = json_decode($concepts); | |
$attendanceIn = strtotime($attendanceIn); | |
$attendanceOut = strtotime($attendanceOut); | |
$response = []; | |
foreach ($concepts as $key => $value) { | |
$start = strtotime($value->start); | |
$end = strtotime($value->end); | |
if (($attendanceIn >= $start && $attendanceIn <= $end)) { | |
$init = $attendanceIn; | |
} | |
else if (($attendanceIn < $start && $attendanceIn <= $end)) { | |
$init = $start; | |
} | |
else { | |
continue; | |
} | |
if ($attendanceOut >= $start && $attendanceOut <= $end) { | |
$finish = $attendanceOut; | |
} | |
else if ($attendanceOut >= $start && $attendanceOut > $end){ | |
$finish = $end; | |
} | |
else { | |
continue; | |
} | |
$diff = $finish - $init; | |
$response[$value->id] = (float)date('H:i', $diff); | |
} | |
return json_encode($response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment