3v4l.org

run code in 300+ PHP versions simultaneously
<?php function addRollover($givenDate, $addtime, $dayStart, $dayEnd, $weekDaysOnly) { //Break the working day start and end times into hours, minuets $dayStart = explode(',', $dayStart); $dayEnd = explode(',', $dayEnd); //Create required datetime objects and hours interval $datetime = new DateTime($givenDate); $endofday = clone $datetime; $endofday->setTime($dayEnd[0], $dayEnd[1]); //set end of working day time $interval = 'PT'.$addtime.'H'; //Add hours onto initial given date $datetime->add(new DateInterval($interval)); //if initial date + hours is after the end of working day if($datetime > $endofday) { //get the difference between the initial date + interval and the end of working day in seconds $seconds = $datetime->getTimestamp()- $endofday->getTimestamp(); //Loop to next day while(true) { $endofday->add(new DateInterval('PT24H'));//Loop to next day by adding 24hrs $nextDay = $endofday->setTime($dayStart[0], $dayStart[1]);//Set day to working day start time //If the next day is on a weekend and the week day only param is true continue to add days if(in_array($nextDay->format('l'), array('Sunday','Saturday')) && $weekDaysOnly) { continue; } else //If not a weekend { $tmpDate = clone $nextDay; $tmpDate->setTime($dayEnd[0], $dayEnd[1]);//clone the next day and set time to working day end time $nextDay->add(new DateInterval('PT'.$seconds.'S')); //add the seconds onto the next day //if the next day time is later than the end of the working day continue loop if($nextDay > $tmpDate) { $seconds = $nextDay->getTimestamp()-$tmpDate->getTimestamp(); $endofday = clone $tmpDate; $endofday->setTime($dayStart[0], $dayStart[1]); } else //else return the new date. { return $endofday; } } } } return $datetime; } $currentTime = '2014-06-27 08:30:00'; $dayStart = '8,30'; $dayEnd = '17,30'; $future = addRollover($currentTime, 65, $dayStart, $dayEnd, true); echo "Results: </br>"; echo $future->format('Y-m-d H:i:s').'</br>';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eKZsE
function name:  (null)
number of ops:  18
compiled vars:  !0 = $currentTime, !1 = $dayStart, !2 = $dayEnd, !3 = $future
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   ASSIGN                                                   !0, '2014-06-27+08%3A30%3A00'
   54     1        ASSIGN                                                   !1, '8%2C30'
   55     2        ASSIGN                                                   !2, '17%2C30'
   57     3        INIT_FCALL                                               'addrollover'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 65
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !2
          8        SEND_VAL                                                 <true>
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !3, $7
   59    11        ECHO                                                     'Results%3A+%3C%2Fbr%3E'
   60    12        INIT_METHOD_CALL                                         !3, 'format'
         13        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         14        DO_FCALL                                      0  $9      
         15        CONCAT                                           ~10     $9, '%3C%2Fbr%3E'
         16        ECHO                                                     ~10
         17      > RETURN                                                   1

Function addrollover:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 110
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
2 jumps found. (Code = 44) Position 1 = 110, Position 2 = 47
Branch analysis from position: 110
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
2 jumps found. (Code = 46) Position 1 = 67, Position 2 = 68
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 71
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 108
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
Branch analysis from position: 108
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 110
filename:       /in/eKZsE
function name:  addRollover
number of ops:  112
compiled vars:  !0 = $givenDate, !1 = $addtime, !2 = $dayStart, !3 = $dayEnd, !4 = $weekDaysOnly, !5 = $datetime, !6 = $endofday, !7 = $interval, !8 = $seconds, !9 = $nextDay, !10 = $tmpDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
    4     5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '%2C'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $11     
          9        ASSIGN                                                   !2, $11
    5    10        INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '%2C'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !3, $13
    7    15        NEW                                              $15     'DateTime'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !5, $15
    8    19        CLONE                                            ~18     !5
         20        ASSIGN                                                   !6, ~18
    9    21        INIT_METHOD_CALL                                         !6, 'setTime'
         22        CHECK_FUNC_ARG                                           
         23        FETCH_DIM_FUNC_ARG                               $20     !3, 0
         24        SEND_FUNC_ARG                                            $20
         25        CHECK_FUNC_ARG                                           
         26        FETCH_DIM_FUNC_ARG                               $21     !3, 1
         27        SEND_FUNC_ARG                                            $21
         28        DO_FCALL                                      0          
   10    29        CONCAT                                           ~23     'PT', !1
         30        CONCAT                                           ~24     ~23, 'H'
         31        ASSIGN                                                   !7, ~24
   12    32        INIT_METHOD_CALL                                         !5, 'add'
         33        NEW                                              $26     'DateInterval'
         34        SEND_VAR_EX                                              !7
         35        DO_FCALL                                      0          
         36        SEND_VAR_NO_REF_EX                                       $26
         37        DO_FCALL                                      0          
   14    38        IS_SMALLER                                               !6, !5
         39      > JMPZ                                                     ~29, ->110
   17    40    >   INIT_METHOD_CALL                                         !5, 'getTimestamp'
         41        DO_FCALL                                      0  $30     
         42        INIT_METHOD_CALL                                         !6, 'getTimestamp'
         43        DO_FCALL                                      0  $31     
         44        SUB                                              ~32     $30, $31
         45        ASSIGN                                                   !8, ~32
   20    46      > JMP                                                      ->109
   22    47    >   INIT_METHOD_CALL                                         !6, 'add'
         48        NEW                                              $34     'DateInterval'
         49        SEND_VAL_EX                                              'PT24H'
         50        DO_FCALL                                      0          
         51        SEND_VAR_NO_REF_EX                                       $34
         52        DO_FCALL                                      0          
   23    53        INIT_METHOD_CALL                                         !6, 'setTime'
         54        CHECK_FUNC_ARG                                           
         55        FETCH_DIM_FUNC_ARG                               $37     !2, 0
         56        SEND_FUNC_ARG                                            $37
         57        CHECK_FUNC_ARG                                           
         58        FETCH_DIM_FUNC_ARG                               $38     !2, 1
         59        SEND_FUNC_ARG                                            $38
         60        DO_FCALL                                      0  $39     
         61        ASSIGN                                                   !9, $39
   25    62        INIT_METHOD_CALL                                         !9, 'format'
         63        SEND_VAL_EX                                              'l'
         64        DO_FCALL                                      0  $41     
         65        IN_ARRAY                                         ~42     $41, <array>
         66      > JMPZ_EX                                          ~42     ~42, ->68
         67    >   BOOL                                             ~42     !4
         68    > > JMPZ                                                     ~42, ->71
   27    69    > > JMP                                                      ->109
         70*       JMP                                                      ->109
   31    71    >   CLONE                                            ~43     !9
         72        ASSIGN                                                   !10, ~43
   32    73        INIT_METHOD_CALL                                         !10, 'setTime'
         74        CHECK_FUNC_ARG                                           
         75        FETCH_DIM_FUNC_ARG                               $45     !3, 0
         76        SEND_FUNC_ARG                                            $45
         77        CHECK_FUNC_ARG                                           
         78        FETCH_DIM_FUNC_ARG                               $46     !3, 1
         79        SEND_FUNC_ARG                                            $46
         80        DO_FCALL                                      0          
   33    81        INIT_METHOD_CALL                                         !9, 'add'
         82        NEW                                              $48     'DateInterval'
         83        CONCAT                                           ~49     'PT', !8
         84        CONCAT                                           ~50     ~49, 'S'
         85        SEND_VAL_EX                                              ~50
         86        DO_FCALL                                      0          
         87        SEND_VAR_NO_REF_EX                                       $48
         88        DO_FCALL                                      0          
   35    89        IS_SMALLER                                               !10, !9
         90      > JMPZ                                                     ~53, ->108
   37    91    >   INIT_METHOD_CALL                                         !9, 'getTimestamp'
         92        DO_FCALL                                      0  $54     
         93        INIT_METHOD_CALL                                         !10, 'getTimestamp'
         94        DO_FCALL                                      0  $55     
         95        SUB                                              ~56     $54, $55
         96        ASSIGN                                                   !8, ~56
   38    97        CLONE                                            ~58     !10
         98        ASSIGN                                                   !6, ~58
   39    99        INIT_METHOD_CALL                                         !6, 'setTime'
        100        CHECK_FUNC_ARG                                           
        101        FETCH_DIM_FUNC_ARG                               $60     !2, 0
        102        SEND_FUNC_ARG                                            $60
        103        CHECK_FUNC_ARG                                           
        104        FETCH_DIM_FUNC_ARG                               $61     !2, 1
        105        SEND_FUNC_ARG                                            $61
        106        DO_FCALL                                      0          
        107      > JMP                                                      ->109
   43   108    > > RETURN                                                   !6
   20   109    > > JMPNZ                                                    <true>, ->47
   49   110    > > RETURN                                                   !5
   50   111*     > RETURN                                                   null

End of function addrollover

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
284.29 ms | 1411 KiB | 17 Q