3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Settings $workStartHour = 9; $workStartMin = 0; $workEndHour = 17; $workEndMin = 30; $workdayHours = 8.5; $weekends = ['Saturday', 'Sunday']; $hours = 0; // Original start and end times, and their clones that we'll modify. $originalStart = new DateTime('2014-06-25 11:30'); $start = clone $originalStart; // Starting on a weekend? Skip to a weekday. while (in_array($start->format('l'), $weekends)) { $start->modify('midnight tomorrow'); } $originalEnd = new DateTime('2014-07-22 12:30'); $end = clone $originalEnd; // Ending on a weekend? Go back to a weekday. while (in_array($end->format('l'), $weekends)) { $end->modify('-1 day')->setTime(23, 59); } // Is the start date after the end date? Might happen if start and end // are on the same weekend (whoops). if ($start > $end) throw new Exception('Start date is AFTER end date!'); // Are the times outside of normal work hours? If so, adjust. $startAdj = clone $start; if ($start < $startAdj->setTime($workStartHour, $workStartMin)) { // Start is earlier; adjust to real start time. $start = $startAdj; } else if ($start > $startAdj->setTime($workEndHour, $workEndMin)) { // Start is after close of that day, move to tomorrow. $start = $startAdj->setTime($workStartHour, $workStartMin)->modify('+1 day'); } $endAdj = clone $end; if ($end > $endAdj->setTime($workEndHour, $workEndMin)) { // End is after; adjust to real end time. $end = $endAdj; } else if ($end < $endAdj->setTime($workStartHour, $workStartMin)) { // End is before start of that day, move to day before. $end = $endAdj->setTime($workEndHour, $workEndMin)->modify('-1 day'); } // Calculate the difference between our modified days. $diff = $start->diff($end); // Go through each day using the original values, so we can check for weekends. $period = new DatePeriod($start, new DateInterval('P1D'), $end); foreach ($period as $day) { // If it's a weekend day, take it out of our total days in the diff. if (in_array($day->format('l'), ['Saturday', 'Sunday'])) $diff->d--; } // Calculate! Days * Hours in a day + hours + minutes converted to hours. $hours = ($diff->d * $workdayHours) + $diff->h + round($diff->i / 60, 2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 14
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 32
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 87
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 101
Branch analysis from position: 101
2 jumps found. (Code = 77) Position 1 = 115, Position 2 = 123
Branch analysis from position: 115
2 jumps found. (Code = 78) Position 1 = 116, Position 2 = 123
Branch analysis from position: 116
2 jumps found. (Code = 43) Position 1 = 121, Position 2 = 122
Branch analysis from position: 121
1 jumps found. (Code = 42) Position 1 = 115
Branch analysis from position: 115
Branch analysis from position: 122
Branch analysis from position: 123
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 123
Branch analysis from position: 87
2 jumps found. (Code = 43) Position 1 = 93, Position 2 = 101
Branch analysis from position: 93
2 jumps found. (Code = 77) Position 1 = 115, Position 2 = 123
Branch analysis from position: 115
Branch analysis from position: 123
Branch analysis from position: 101
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 77
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 87
Branch analysis from position: 85
Branch analysis from position: 87
Branch analysis from position: 77
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 32
Branch analysis from position: 47
Branch analysis from position: 32
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 14
Branch analysis from position: 25
Branch analysis from position: 14
filename:       /in/NeO5M
function name:  (null)
number of ops:  137
compiled vars:  !0 = $workStartHour, !1 = $workStartMin, !2 = $workEndHour, !3 = $workEndMin, !4 = $workdayHours, !5 = $weekends, !6 = $hours, !7 = $originalStart, !8 = $start, !9 = $originalEnd, !10 = $end, !11 = $startAdj, !12 = $endAdj, !13 = $diff, !14 = $period, !15 = $day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 9
    4     1        ASSIGN                                                   !1, 0
    5     2        ASSIGN                                                   !2, 17
    6     3        ASSIGN                                                   !3, 30
    7     4        ASSIGN                                                   !4, 8.5
    8     5        ASSIGN                                                   !5, <array>
    9     6        ASSIGN                                                   !6, 0
   12     7        NEW                                              $23     'DateTime'
          8        SEND_VAL_EX                                              '2014-06-25+11%3A30'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !7, $23
   13    11        CLONE                                            ~26     !7
         12        ASSIGN                                                   !8, ~26
   16    13      > JMP                                                      ->17
   18    14    >   INIT_METHOD_CALL                                         !8, 'modify'
         15        SEND_VAL_EX                                              'midnight+tomorrow'
         16        DO_FCALL                                      0          
   16    17    >   INIT_FCALL                                               'in_array'
         18        INIT_METHOD_CALL                                         !8, 'format'
         19        SEND_VAL_EX                                              'l'
         20        DO_FCALL                                      0  $29     
         21        SEND_VAR                                                 $29
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $30     
         24      > JMPNZ                                                    $30, ->14
   21    25    >   NEW                                              $31     'DateTime'
         26        SEND_VAL_EX                                              '2014-07-22+12%3A30'
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !9, $31
   22    29        CLONE                                            ~34     !9
         30        ASSIGN                                                   !10, ~34
   25    31      > JMP                                                      ->39
   27    32    >   INIT_METHOD_CALL                                         !10, 'modify'
         33        SEND_VAL_EX                                              '-1+day'
         34        DO_FCALL                                      0  $36     
         35        INIT_METHOD_CALL                                         $36, 'setTime'
         36        SEND_VAL_EX                                              23
         37        SEND_VAL_EX                                              59
         38        DO_FCALL                                      0          
   25    39    >   INIT_FCALL                                               'in_array'
         40        INIT_METHOD_CALL                                         !10, 'format'
         41        SEND_VAL_EX                                              'l'
         42        DO_FCALL                                      0  $38     
         43        SEND_VAR                                                 $38
         44        SEND_VAR                                                 !5
         45        DO_ICALL                                         $39     
         46      > JMPNZ                                                    $39, ->32
   32    47    >   IS_SMALLER                                               !10, !8
         48      > JMPZ                                                     ~40, ->53
         49    >   NEW                                              $41     'Exception'
         50        SEND_VAL_EX                                              'Start+date+is+AFTER+end+date%21'
         51        DO_FCALL                                      0          
         52      > THROW                                         0          $41
   35    53    >   CLONE                                            ~43     !8
         54        ASSIGN                                                   !11, ~43
   37    55        INIT_METHOD_CALL                                         !11, 'setTime'
         56        SEND_VAR_EX                                              !0
         57        SEND_VAR_EX                                              !1
         58        DO_FCALL                                      0  $45     
         59        IS_SMALLER                                               !8, $45
         60      > JMPZ                                                     ~46, ->63
   40    61    >   ASSIGN                                                   !8, !11
         62      > JMP                                                      ->77
   42    63    >   INIT_METHOD_CALL                                         !11, 'setTime'
         64        SEND_VAR_EX                                              !2
         65        SEND_VAR_EX                                              !3
         66        DO_FCALL                                      0  $48     
         67        IS_SMALLER                                               $48, !8
         68      > JMPZ                                                     ~49, ->77
   45    69    >   INIT_METHOD_CALL                                         !11, 'setTime'
         70        SEND_VAR_EX                                              !0
         71        SEND_VAR_EX                                              !1
         72        DO_FCALL                                      0  $50     
         73        INIT_METHOD_CALL                                         $50, 'modify'
         74        SEND_VAL_EX                                              '%2B1+day'
         75        DO_FCALL                                      0  $51     
         76        ASSIGN                                                   !8, $51
   48    77    >   CLONE                                            ~53     !10
         78        ASSIGN                                                   !12, ~53
   50    79        INIT_METHOD_CALL                                         !12, 'setTime'
         80        SEND_VAR_EX                                              !2
         81        SEND_VAR_EX                                              !3
         82        DO_FCALL                                      0  $55     
         83        IS_SMALLER                                               $55, !10
         84      > JMPZ                                                     ~56, ->87
   53    85    >   ASSIGN                                                   !10, !12
         86      > JMP                                                      ->101
   55    87    >   INIT_METHOD_CALL                                         !12, 'setTime'
         88        SEND_VAR_EX                                              !0
         89        SEND_VAR_EX                                              !1
         90        DO_FCALL                                      0  $58     
         91        IS_SMALLER                                               !10, $58
         92      > JMPZ                                                     ~59, ->101
   58    93    >   INIT_METHOD_CALL                                         !12, 'setTime'
         94        SEND_VAR_EX                                              !2
         95        SEND_VAR_EX                                              !3
         96        DO_FCALL                                      0  $60     
         97        INIT_METHOD_CALL                                         $60, 'modify'
         98        SEND_VAL_EX                                              '-1+day'
         99        DO_FCALL                                      0  $61     
        100        ASSIGN                                                   !10, $61
   62   101    >   INIT_METHOD_CALL                                         !8, 'diff'
        102        SEND_VAR_EX                                              !10
        103        DO_FCALL                                      0  $63     
        104        ASSIGN                                                   !13, $63
   65   105        NEW                                              $65     'DatePeriod'
        106        SEND_VAR_EX                                              !8
        107        NEW                                              $66     'DateInterval'
        108        SEND_VAL_EX                                              'P1D'
        109        DO_FCALL                                      0          
        110        SEND_VAR_NO_REF_EX                                       $66
        111        SEND_VAR_EX                                              !10
        112        DO_FCALL                                      0          
        113        ASSIGN                                                   !14, $65
   67   114      > FE_RESET_R                                       $70     !14, ->123
        115    > > FE_FETCH_R                                               $70, !15, ->123
   70   116    >   INIT_METHOD_CALL                                         !15, 'format'
        117        SEND_VAL_EX                                              'l'
        118        DO_FCALL                                      0  $71     
        119        IN_ARRAY                                                 $71, <array>
        120      > JMPZ                                                     ~72, ->122
        121    >   PRE_DEC_OBJ                                              !13, 'd'
   67   122    > > JMP                                                      ->115
        123    >   FE_FREE                                                  $70
   74   124        FETCH_OBJ_R                                      ~74     !13, 'd'
        125        MUL                                              ~75     !4, ~74
        126        FETCH_OBJ_R                                      ~76     !13, 'h'
        127        ADD                                              ~77     ~75, ~76
        128        INIT_FCALL                                               'round'
        129        FETCH_OBJ_R                                      ~78     !13, 'i'
        130        DIV                                              ~79     ~78, 60
        131        SEND_VAL                                                 ~79
        132        SEND_VAL                                                 2
        133        DO_ICALL                                         $80     
        134        ADD                                              ~81     ~77, $80
        135        ASSIGN                                                   !6, ~81
        136      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.52 ms | 1408 KiB | 17 Q