Skip to content

Instantly share code, notes, and snippets.

@mbriceno
Created February 1, 2023 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbriceno/af2c9898f36de9e837555eb63165267d to your computer and use it in GitHub Desktop.
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.
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