3v4l.org

run code in 300+ PHP versions simultaneously
<?php //function checkDeliveryPeriod(bool $isGas = false) //{ // $startDate = new DateTime('2020-08-01 00:00:00'); // $endDate = new DateTime('2024-02-16'); // // initial // $originReadAt = new DateTime('2024-02-17 00:00:00'); // $readAt = clone $originReadAt; // if ($isGas && $endDate !== null && $readAt > $endDate) { // //Gas day case: gas day ends at 6:00 next day // $readAt->subHours(6); // } // $readAt->setTime(0, 0, 0); // // // assure contract start date // if ($startDate == null) { // return false; // } // //special case when the start and end dates of the contract are the same // $startEndOnSameDay = ( // ($originReadAt->format('H:i') == '00:00') // && ($endDate === $startDate) // ); // // final check // return ( // $readAt >= $startDate // && ( // $endDate === null // || ($endDate !== null && $readAt <= $endDate) // ) // ) || $startEndOnSameDay; //} // //var_dump(checkDeliveryPeriod()); function determineNewRunAt(\DateTimeInterface $createdAt): DateTime { $nextRunAt = new DateTime(); $oneMonth = (clone $createdAt)->modify('1month'); $diff = $nextRunAt->diff($createdAt); var_dump($diff->days, $diff->h); // time out after one month after creation if ($nextRunAt >= $oneMonth) { throw new \Exception('Waiting time expired'); } // run the action once a day, if it was not finished within 1 day after creation if ($diff->days >= 1) { return $nextRunAt->modify('1day'); } return $diff->h === 0 ? $nextRunAt->modify('5minute') // run the action every 5 minutes within the first hour after creation : $nextRunAt->modify('1hour'); // run the action every hour for one day after creation } $nextRunAt = determineNewRunAt(new DateTime('2024-04-10 07:15')); var_dump($nextRunAt->format('Y-m-d h:i:s')); $nextRunAt = determineNewRunAt(new DateTime('2024-04-10 06:15')); var_dump($nextRunAt->format('Y-m-d h:i:s')); $nextRunAt = determineNewRunAt(new DateTime('2024-04-09 06:15')); var_dump($nextRunAt->format('Y-m-d h:i:s')); try { $nextRunAt = determineNewRunAt(new DateTime('2024-03-09 06:15')); } catch (\Throwable $e) { var_dump($e->getMessage()); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 47
Branch analysis from position: 47
2 jumps found. (Code = 107) Position 1 = 48, Position 2 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vTsUP
function name:  (null)
number of ops:  54
compiled vars:  !0 = $nextRunAt, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   INIT_FCALL                                               'determinenewrunat'
          1        NEW                                              $2      'DateTime'
          2        SEND_VAL_EX                                              '2024-04-10+07%3A15'
          3        DO_FCALL                                      0          
          4        SEND_VAR                                                 $2
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !0, $4
   60     7        INIT_FCALL                                               'var_dump'
          8        INIT_METHOD_CALL                                         !0, 'format'
          9        SEND_VAL_EX                                              'Y-m-d+h%3Ai%3As'
         10        DO_FCALL                                      0  $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                                 
   61    13        INIT_FCALL                                               'determinenewrunat'
         14        NEW                                              $8      'DateTime'
         15        SEND_VAL_EX                                              '2024-04-10+06%3A15'
         16        DO_FCALL                                      0          
         17        SEND_VAR                                                 $8
         18        DO_FCALL                                      0  $10     
         19        ASSIGN                                                   !0, $10
   62    20        INIT_FCALL                                               'var_dump'
         21        INIT_METHOD_CALL                                         !0, 'format'
         22        SEND_VAL_EX                                              'Y-m-d+h%3Ai%3As'
         23        DO_FCALL                                      0  $12     
         24        SEND_VAR                                                 $12
         25        DO_ICALL                                                 
   63    26        INIT_FCALL                                               'determinenewrunat'
         27        NEW                                              $14     'DateTime'
         28        SEND_VAL_EX                                              '2024-04-09+06%3A15'
         29        DO_FCALL                                      0          
         30        SEND_VAR                                                 $14
         31        DO_FCALL                                      0  $16     
         32        ASSIGN                                                   !0, $16
   64    33        INIT_FCALL                                               'var_dump'
         34        INIT_METHOD_CALL                                         !0, 'format'
         35        SEND_VAL_EX                                              'Y-m-d+h%3Ai%3As'
         36        DO_FCALL                                      0  $18     
         37        SEND_VAR                                                 $18
         38        DO_ICALL                                                 
   66    39        INIT_FCALL                                               'determinenewrunat'
         40        NEW                                              $20     'DateTime'
         41        SEND_VAL_EX                                              '2024-03-09+06%3A15'
         42        DO_FCALL                                      0          
         43        SEND_VAR                                                 $20
         44        DO_FCALL                                      0  $22     
         45        ASSIGN                                                   !0, $22
         46      > JMP                                                      ->53
   67    47  E > > CATCH                                       last         'Throwable'
   68    48    >   INIT_FCALL                                               'var_dump'
         49        INIT_METHOD_CALL                                         !1, 'getMessage'
         50        DO_FCALL                                      0  $24     
         51        SEND_VAR                                                 $24
         52        DO_ICALL                                                 
   69    53    > > RETURN                                                   1

Function determinenewrunat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vTsUP
function name:  determineNewRunAt
number of ops:  49
compiled vars:  !0 = $createdAt, !1 = $nextRunAt, !2 = $oneMonth, !3 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        NEW                                              $4      'DateTime'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $4
   42     4        CLONE                                            ~7      !0
          5        INIT_METHOD_CALL                                         ~7, 'modify'
          6        SEND_VAL_EX                                              '1month'
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !2, $8
   43     9        INIT_METHOD_CALL                                         !1, 'diff'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !3, $10
   44    13        INIT_FCALL                                               'var_dump'
         14        FETCH_OBJ_R                                      ~12     !3, 'days'
         15        SEND_VAL                                                 ~12
         16        FETCH_OBJ_R                                      ~13     !3, 'h'
         17        SEND_VAL                                                 ~13
         18        DO_ICALL                                                 
   46    19        IS_SMALLER_OR_EQUAL                                      !2, !1
         20      > JMPZ                                                     ~15, ->25
   47    21    >   NEW                                              $16     'Exception'
         22        SEND_VAL_EX                                              'Waiting+time+expired'
         23        DO_FCALL                                      0          
         24      > THROW                                         0          $16
   51    25    >   FETCH_OBJ_R                                      ~18     !3, 'days'
         26        IS_SMALLER_OR_EQUAL                                      1, ~18
         27      > JMPZ                                                     ~19, ->33
   52    28    >   INIT_METHOD_CALL                                         !1, 'modify'
         29        SEND_VAL_EX                                              '1day'
         30        DO_FCALL                                      0  $20     
         31        VERIFY_RETURN_TYPE                                       $20
         32      > RETURN                                                   $20
   55    33    >   FETCH_OBJ_R                                      ~21     !3, 'h'
         34        IS_IDENTICAL                                             ~21, 0
         35      > JMPZ                                                     ~22, ->41
   56    36    >   INIT_METHOD_CALL                                         !1, 'modify'
         37        SEND_VAL_EX                                              '5minute'
         38        DO_FCALL                                      0  $23     
         39        QM_ASSIGN                                        ~24     $23
         40      > JMP                                                      ->45
   57    41    >   INIT_METHOD_CALL                                         !1, 'modify'
         42        SEND_VAL_EX                                              '1hour'
         43        DO_FCALL                                      0  $25     
         44        QM_ASSIGN                                        ~24     $25
         45    >   VERIFY_RETURN_TYPE                                       ~24
         46      > RETURN                                                   ~24
   58    47*       VERIFY_RETURN_TYPE                                       
         48*     > RETURN                                                   null

End of function determinenewrunat

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.92 ms | 1022 KiB | 18 Q