@ 2019-07-26T03:21:33Z <?php
$punch_in = "2019-07-01 09:00:00";
$punch_out = "2019-07-01 18:00:00";
$in_threshold = "2019-07-01 08:15:00";
$out_threshold = "2019-07-01 17:15:00";
$exact_in_threshold = "2019-07-01 08:00:00";
$exact_out_threshold = "2019-07-01 17:00:00";
function generateAttendance( $punch_in, $punch_out , $in_threshold, $out_threshold , $exact_in_threshold, $exact_out_threshold){
$lates = 0;
$overtime = 0;
// If punch_in is late = punch_in and late + 1
if ($punch_in > $in_threshold) {
$start = $punch_in;
$lates = +1;
}
// If punch_in is early = exact_time
else {
$start = $exact_in_threshold;
}
// If punch_out is early = punch_out
if ($punch_out < $out_threshold) {
$end = $punch_out;
}
// If pucn_out is overtime = exact_end and overtime + 1
else {
$end = $exact_out_threshold;
$overtime =1;
}
// If both punch in and punch_out is within threshold
if ((( $exact_in_threshold >= $in_threshold ) && ( $exact_in_threshold <= $punch_in ))
&& (( $exact_out_threshold >= $out_threshold ) && ( $exact_out_threshold <= $punch_out ))) {
$start = $punch_in;
$end = $punch_out;
}
// If punch_in is within threshold, start = punch_in and end = exact_end
else if ((( $exact_in_threshold >= $in_threshold ) && ( $exact_in_threshold <= $punch_in )) && $punch_out > $out_threshold) {
$start = $punch_in;
$end = $exact_out_threshold;
}
return array('start' => $start, 'end' => $end, 'lates' => $lates, 'overtime' => $overtime);
}
$result = generateAttendance( $punch_in, $punch_out , $in_threshold, $out_threshold , $exact_in_threshold, $exact_out_threshold);
print_r($result);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 Array
(
[start] => 2019-07-01 09:00:00
[end] => 2019-07-01 17:00:00
[lates] => 1
[overtime] => 1
)
Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Array
(
[start] => 2019-07-01 09:00:00
[end] => 2019-07-01 17:00:00
[lates] => 1
[overtime] => 1
)
preferences:dark mode live preview
216.69 ms | 402 KiB | 210 Q