3v4l.org

run code in 300+ PHP versions simultaneously
<?php $attendance = [ "2019-07-01 08:00:00", "2019-07-01 12:00:00", "2019-07-01 13:00:00", "2019-07-01 17:00:00", ]; /** TEST CASES: // Late $attendance = [ "2019-07-01 08:35:00", "2019-07-01 12:00:00", "2019-07-01 13:00:00", "2019-07-01 17:00:00", ]; // Early $attendance = [ "2019-07-01 07:45:00", "2019-07-01 12:00:00", "2019-07-01 13:00:00", "2019-07-01 17:00:00", ]; */ $schedules = [ [ "time_start" => "08:00:00", "time_end" => "12:00:00", "in_threshold" => 15, "out_threshold" => 15 ], [ "time_start" => "13:00:00", "time_end" => "17:00:00", "in_threshold" => 15, "out_threshold" => 15 ] ]; // If date is between $from and $to function isBetween( $from, $to, $date ) { return ( $date > $from ) && ( $date <= $to ); } // Get ClosestTime in schedules time_start and time_end function getClosestTime( $array, $date ){ foreach( $array as $day ){ $interval[] = abs(strtotime($date) - strtotime($day)); } asort($interval); $closest = key($interval); return $array[$closest]; } // Store time_start and time_end to array foreach($schedules as $schedule){ // Set time_start and time_end with threshold $mytime_start[] = date( "H:i:s", strtotime('+'. $schedule[ 'in_threshold' ] .' minutes', strtotime ( $schedule[ 'time_start' ] ))); $mytime_end[] = date( "H:i:s", strtotime('+'. $schedule[ 'out_threshold' ] .' minutes', strtotime( $schedule[ 'time_end' ] ))); // Get time_start and time_end to array $sched_starts[] = ( $schedule[ 'time_start' ] ); $sched_ends[] = ( $schedule[ 'time_end' ] ); } // Initialized array $total_garner_hours = 0; $total_late = 0; // Get attendance record by 2 for ($index = 0; $index < count($attendance); $index += 2) { $date_start = $attendance[$index]; // Punch In $date_end = $attendance[$index + 1]; // Punch Out // Get Dates from time_in and time_out (for dates cross midnight) $to_date_start = date("Y-m-d", strtotime($date_start)); $to_date_end = date("Y-m-d", strtotime($date_end)); // Get Closest time schedule $time_start = getClosestTime($mytime_start, date('H:i:s',strtotime($date_start))); $time_end = getClosestTime($mytime_end, date('H:i:s',strtotime($date_end))); // Set check in to time start if its greater than time end if ($time_start > $time_end) { $time_start = date("Y-m-d", strtotime($date_start)); } // Set date to datetime from $to_date_start / $to_date_end $time_start = date('Y-m-d H:i:s', strtotime("$to_date_start $time_start")); $time_end = date('Y-m-d H:i:s', strtotime("$to_date_end $time_end")); // Remove threshold Eg. 08:15:00 to 08:00:00 $time_minus_start = date("Y-m-d H:i:s", strtotime("-15 minutes $time_start")); $time_minus_end = date("Y-m-d H:i:s", strtotime("-15 minutes $time_end")); // Sets variables to make it more readable $within_in = $late = strtotime($date_start); $within_out = $early = strtotime($date_end); $exact_in = strtotime($time_minus_start); $exact_out = strtotime($time_minus_end); $late_out = strtotime($time_end); // Check if date_start is Early or Exact if ($date_start > $time_start) { $start = $late; $total_late += 1; }else { $start = $exact_in; } // Check if date_end is Early or Exact ($date_end < $time_end) ? $end = $early : $end = $exact_out; // If date_start is between 08:00:00 and 08:15:00 and date_end is between 12:00:00 and 12:15:00 // return its date if (isBetween($time_minus_start, $time_start, $date_start) && isBetween($time_minus_end, $time_end, $date_end)) { $start = $within_in; $end = $within_out; } else if (isBetween($time_minus_start, $time_start, $date_start) && $date_end > $time_end) { $start = $within_in; $end = $late_out; } // Sum the total garnered hours $total_garner_hours += ($end - $start); } $total_hours = floor($total_garner_hours / 3600); echo ('Total Hours:'.$total_hours); echo '<br>'; echo ('Late: '.$total_late);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0090.00916.88
8.3.50.0140.00522.12
8.3.40.0100.00619.10
8.3.30.0090.00918.87
8.3.20.0000.00821.90
8.3.10.0070.01119.96
8.3.00.0000.00922.52
8.2.180.0150.00316.75
8.2.170.0150.00022.96
8.2.160.0110.00419.59
8.2.150.0000.01024.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0080.00021.11
8.2.110.0100.00022.27
8.2.100.0100.00318.16
8.2.90.0080.00018.34
8.2.80.0030.00519.36
8.2.70.0040.00418.00
8.2.60.0040.00419.60
8.2.50.0000.00817.88
8.2.40.0060.00317.75
8.2.30.0040.00419.36
8.2.20.0000.00818.36
8.2.10.0080.00019.55
8.2.00.0000.00719.48
8.1.280.0130.00325.92
8.1.270.0080.00023.91
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0000.00924.02
8.1.230.0090.00920.95
8.1.220.0050.00317.77
8.1.210.0030.00618.78
8.1.200.0160.00317.61
8.1.190.0050.00317.48
8.1.180.0040.00418.10
8.1.170.0030.00519.03
8.1.160.0030.00518.99
8.1.150.0030.00518.96
8.1.140.0040.00421.01
8.1.130.0000.00720.29
8.1.120.0040.00417.77
8.1.110.0050.00317.75
8.1.100.0080.00017.69
8.1.90.0080.00017.73
8.1.80.0000.00717.79
8.1.70.0060.00317.77
8.1.60.0050.00317.81
8.1.50.0000.00817.84
8.1.40.0080.00017.66
8.1.30.0000.00817.89
8.1.20.0000.00817.72
8.1.10.0050.00317.75
8.1.00.0000.00817.80
8.0.300.0040.00420.34
8.0.290.0040.00417.00
8.0.280.0000.00718.63
8.0.270.0000.00817.10
8.0.260.0000.00820.11
8.0.250.0040.00317.17
8.0.240.0000.00617.20
8.0.230.0070.00017.18
8.0.220.0040.00417.24
8.0.210.0080.00017.17
8.0.200.0000.00817.15
8.0.190.0080.00017.30
8.0.180.0040.00417.25
8.0.170.0030.00517.20
8.0.160.0070.00017.18
8.0.150.0080.00017.15
8.0.140.0050.00217.12
8.0.130.0030.00313.62
8.0.120.0000.00717.17
8.0.110.0080.00017.14
8.0.100.0000.00817.08
8.0.90.0090.00017.07
8.0.80.0040.01117.18
8.0.70.0000.00817.13
8.0.60.0040.00417.19
8.0.50.0000.00817.26
8.0.30.0050.01317.38
8.0.20.0210.02717.52
8.0.10.0070.00017.25
8.0.00.0090.00917.01
7.4.330.0060.00015.55
7.4.320.0030.00316.84
7.4.300.0000.00616.88
7.4.290.0000.00816.68
7.4.280.0000.00816.83
7.4.270.0040.00416.73
7.4.260.0000.00716.87
7.4.250.0080.00016.86
7.4.240.0000.00716.86
7.4.230.0030.00616.64
7.4.220.0030.00416.90
7.4.210.0070.00816.79
7.4.200.0000.00716.77
7.4.140.0070.01817.86
7.4.130.0150.00816.86
7.4.120.0150.00616.80
7.4.110.0120.00616.65
7.4.100.0100.00916.71
7.4.90.0070.01816.73
7.4.80.0200.01319.39
7.4.70.0100.00616.86
7.4.60.0060.01016.68
7.4.50.0030.01316.90
7.4.40.0160.00816.84
7.4.00.0070.01015.37
7.3.330.0030.00313.44
7.3.320.0000.00613.38
7.3.310.0070.00016.64
7.3.300.0070.00016.61
7.3.290.0030.00316.62
7.3.280.0060.00816.61
7.3.260.0110.00916.80
7.3.240.0110.00816.70
7.3.230.0060.01816.81
7.3.210.0130.01016.71
7.3.200.0090.01516.80
7.3.190.0140.00716.66
7.3.180.0040.01416.86
7.3.170.0130.00616.82
7.3.160.0170.00716.86
7.3.120.0040.01415.19
7.3.110.0060.00815.07
7.3.100.0040.01214.97
7.3.90.0090.00715.02
7.3.80.0070.00815.13
7.3.70.0060.00615.09
7.3.60.0110.00714.94
7.3.50.0130.00615.06
7.3.40.0110.00914.96
7.3.30.0080.01015.03
7.3.20.0110.00616.65
7.3.10.0090.01116.75
7.3.00.0070.01016.97
7.2.330.0150.00417.05
7.2.320.0060.01216.86
7.2.310.0070.01117.11
7.2.300.0030.01517.07
7.2.290.0040.01316.91
7.2.250.0060.01215.54
7.2.240.0100.00815.48
7.2.230.0110.00415.27
7.2.220.0060.00814.97
7.2.210.0080.00715.45
7.2.200.0070.01215.32
7.2.190.0070.01015.14
7.2.180.0120.00615.16
7.2.170.0130.00715.38
7.2.160.0100.00915.27
7.2.150.0130.00717.09
7.2.140.0110.00917.13
7.2.130.0060.01416.96
7.2.120.0140.00517.17
7.2.110.0090.00717.09
7.2.100.0090.01117.13
7.2.90.0100.00816.99
7.2.80.0110.00916.97
7.2.70.0080.01116.92
7.2.60.0100.00717.18
7.2.50.0020.01517.23
7.2.40.0090.00817.16
7.2.30.0130.00717.05
7.2.20.0060.01216.94
7.2.10.0090.00917.11
7.2.00.0080.00717.06
7.1.330.0100.00515.88
7.1.320.0090.00515.89
7.1.310.0070.00716.05
7.1.300.0080.01315.98
7.1.290.0110.01015.24
7.1.280.0110.00615.83
7.1.270.0060.01015.84
7.1.260.0090.00815.91
7.1.250.0040.01315.97
7.1.240.0030.01515.71
7.1.230.0100.01016.03
7.1.220.0090.00915.96
7.1.210.0100.01015.99
7.1.200.0000.01516.07
7.1.190.0150.00315.96
7.1.180.0040.01516.13
7.1.170.0080.01215.97
7.1.160.0120.00316.07
7.1.150.0040.01416.11
7.1.140.0060.00815.80
7.1.130.0000.01415.63
7.1.120.0060.00915.78
7.1.110.0080.00615.72
7.1.100.0060.01415.91
7.1.90.0140.00416.02
7.1.80.0100.00915.88
7.1.70.0040.01115.81
7.1.60.0000.02016.06
7.1.50.0080.00816.12
7.1.40.0030.01116.10
7.1.30.0150.00315.73
7.1.20.0070.01415.97
7.1.10.0140.00516.13
7.1.00.0110.01115.96
7.0.330.0060.01415.64
7.0.320.0000.01415.54
7.0.310.0120.00415.25
7.0.300.0090.00615.42
7.0.290.0040.01015.55
7.0.280.0120.00315.43
7.0.270.0000.01515.20
7.0.260.0110.00315.54
7.0.250.0120.00315.26
7.0.240.0150.00315.61
7.0.230.0130.00015.59
7.0.220.0120.00615.50
7.0.210.0110.00315.46
7.0.200.0120.00715.58
7.0.190.0060.01315.72
7.0.180.0030.01115.57
7.0.170.0060.00815.34
7.0.160.0130.00615.56
7.0.150.0070.00715.49
7.0.140.0110.00915.57
7.0.130.0090.00615.30
7.0.120.0050.01015.71
7.0.110.0100.00315.42
7.0.100.0000.01515.61
7.0.90.0040.01415.66
7.0.80.0120.00315.55
7.0.70.0030.01015.31
7.0.60.0060.00915.54
7.0.50.0000.01815.50
7.0.40.0130.00315.61
7.0.30.0130.00015.74
7.0.20.0090.01013.95
7.0.10.0030.01115.46
7.0.00.0090.00915.48
5.6.400.0050.01014.80
5.6.390.0130.00314.62
5.6.380.0100.00614.48
5.6.370.0180.01314.90
5.6.360.0040.02114.66
5.6.350.0200.01014.61
5.6.340.0120.00914.44
5.6.330.0150.00714.55
5.6.320.0120.01214.55
5.6.310.0130.01414.78
5.6.300.0190.00614.50
5.6.290.0120.01014.58
5.6.280.0090.01214.49
5.6.270.0060.01514.68
5.6.260.0060.00914.78
5.6.250.0150.00714.75
5.6.240.0180.00514.73
5.6.230.0160.00714.42
5.6.220.0170.00914.36
5.6.210.0200.00414.23
5.6.200.0170.00414.55
5.6.190.0180.00614.51
5.6.180.0110.00614.57
5.6.170.0070.01014.47
5.6.160.0130.00614.25
5.6.150.0120.00514.49
5.6.140.0110.00814.46
5.6.130.0090.00914.71
5.6.120.0110.01114.68
5.6.110.0120.00414.50
5.6.100.0070.01014.36
5.6.90.0100.01314.48
5.6.80.0180.00914.52
5.6.70.0140.01414.18
5.6.60.0160.00314.70
5.6.50.0210.00314.30
5.6.40.0240.00914.60
5.6.30.0160.00414.51
5.6.20.0150.00714.42
5.6.10.0180.00314.62
5.6.00.0130.00714.20
5.5.380.0110.01114.64
5.5.370.0180.01014.52
5.5.360.0170.00714.33
5.5.350.0130.00814.49
5.5.340.0100.01014.68
5.5.330.0140.00714.75
5.5.320.0060.00914.57
5.5.310.0100.01014.39
5.5.300.0170.00614.41
5.5.290.0150.00714.61
5.5.280.0170.00714.40
5.5.270.0170.00614.11
5.5.260.0180.00314.53
5.5.250.0180.01114.36
5.5.240.0120.01214.59
5.5.230.0120.01614.43
5.5.220.0100.01014.27
5.5.210.0130.01314.48
5.5.200.0250.01614.43
5.5.190.0140.01114.46
5.5.180.0210.00614.34
5.5.170.0140.01114.38
5.5.160.0160.00414.61
5.5.150.0150.00614.67
5.5.140.0140.00614.49
5.5.130.0090.01014.52
5.5.120.0120.00814.33
5.5.110.0130.00514.57
5.5.100.0050.01414.41
5.5.90.0090.01414.38
5.5.80.0170.00414.58
5.5.70.0080.01814.57
5.5.60.0140.01014.63
5.5.50.0150.01114.13
5.5.40.0150.00614.56
5.5.30.0140.00814.54
5.5.20.0160.00814.43
5.5.10.0120.00914.66
5.5.00.0140.00814.69
5.4.450.0110.00711.84
5.4.440.0140.00411.84
5.4.430.0080.00811.84
5.4.420.0120.00411.84
5.4.410.0100.01011.84
5.4.400.0090.00611.84
5.4.390.0130.00311.84
5.4.380.0000.01611.84
5.4.370.0170.00611.84
5.4.360.0150.01211.84
5.4.350.0110.00511.84
5.4.340.0160.00411.84
5.4.330.0150.00211.84
5.4.320.0120.00511.84
5.4.310.0140.00011.84
5.4.300.0070.00711.84
5.4.290.0110.00211.84
5.4.280.0090.00911.84
5.4.270.0120.00411.84
5.4.260.0120.00311.84
5.4.250.0080.00811.84
5.4.240.0090.00911.84
5.4.230.0150.00611.84
5.4.220.0130.00511.84
5.4.210.0070.00711.84
5.4.200.0110.00811.84
5.4.190.0110.01111.84
5.4.180.0150.00311.84
5.4.170.0100.00611.84
5.4.160.0130.00311.84
5.4.150.0100.00511.84
5.4.140.0110.00511.84
5.4.130.0150.00611.84
5.4.120.0110.00511.84
5.4.110.0120.00611.84
5.4.100.0120.00411.84
5.4.90.0100.00711.84
5.4.80.0050.01011.84
5.4.70.0120.00611.84
5.4.60.0050.01011.84
5.4.50.0070.00711.84
5.4.40.0120.00611.84
5.4.30.0110.00411.84
5.4.20.0110.00411.84
5.4.10.0110.00411.84
5.4.00.0070.00711.84
5.3.290.0140.00011.84
5.3.280.0080.00811.84
5.3.270.0100.00711.84
5.3.260.0090.00611.84
5.3.250.0100.01011.84
5.3.240.0100.01411.84
5.3.230.0110.00311.84
5.3.220.0070.00711.84
5.3.210.0130.00011.84
5.3.200.0080.00811.84
5.3.190.0000.01511.84
5.3.180.0150.00311.84
5.3.170.0120.00311.84
5.3.160.0180.00311.84
5.3.150.0080.00511.84
5.3.140.0090.00411.84
5.3.130.0140.00311.84
5.3.120.0100.00311.84
5.3.110.0070.00711.84
5.3.100.0140.00011.84
5.3.90.0100.00711.84
5.3.80.0140.00411.84
5.3.70.0140.00011.84
5.3.60.0070.00711.84
5.3.50.0110.00311.84
5.3.40.0130.00011.84
5.3.30.0080.00411.84
5.3.20.0060.00611.84
5.3.10.0070.00911.84
5.3.00.0080.00411.84
5.2.170.0100.00011.84
5.2.160.0110.00011.84
5.2.150.0000.00911.84
5.2.140.0060.00311.84
5.2.130.0030.00711.84
5.2.120.0000.01111.84
5.2.110.0040.00711.84
5.2.100.0110.00011.84
5.2.90.0110.00011.84
5.2.80.0060.00511.84
5.2.70.0090.00311.84
5.2.60.0070.00411.84
5.2.50.0030.00711.84
5.2.40.0110.00011.84
5.2.30.0100.00011.84
5.2.20.0070.00711.84
5.2.10.0090.00311.84
5.2.00.0050.00511.84
5.1.60.0080.00311.84
5.1.50.0100.00011.84
5.1.40.0030.00711.84
5.1.30.0040.00511.84
5.1.20.0060.00611.84
5.1.10.0020.00911.84
5.1.00.0050.00511.84
5.0.50.0000.00811.84
5.0.40.0030.00611.84
5.0.30.0070.00311.84
5.0.20.0050.00311.84
5.0.10.0050.00511.84
5.0.00.0000.01111.84
4.4.90.0000.00811.84
4.4.80.0060.00211.84
4.4.70.0020.00411.84
4.4.60.0030.00311.84
4.4.50.0040.00211.84
4.4.40.0000.00811.84
4.4.30.0070.00011.84
4.4.20.0040.00411.84
4.4.10.0030.00311.84
4.4.00.0030.00311.84
4.3.110.0070.00011.84
4.3.100.0000.00711.84
4.3.90.0060.00011.84
4.3.80.0070.00011.84
4.3.70.0030.00311.84
4.3.60.0060.00011.84
4.3.50.0030.00311.84
4.3.40.0060.00011.84
4.3.30.0060.00011.84
4.3.20.0020.00411.84
4.3.10.0050.00311.84
4.3.00.0000.00911.84

preferences:
34.9 ms | 401 KiB | 5 Q