3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo getSquadRotation("2014-01-17"); function getSquadRotation($inDate) { //Set timezone: date_default_timezone_set('America/New_York'); //$inDate = "2014-01-17"; //test date $content = explode('-', $inDate); $inDate = mktime(0, 0, 0, $content[1], $content[2], $content[0]); $seedTime = mktime(0, 0, 0, 12, 23, 2013); //Seed timestamp //Seed date (12/23/2013) A squad started on a Monday; let's see if this week is "Week1" or "Week2": //Week 1: Mon: A / Tues: A / Wed: B / Thurs: B / Fri: A / Sat: A / Sun: A //Week 2: Mon: B / Tues: B / Wed: A / Thurs: A / Fri: B / Sat: B / Sun: B //First, let's get the Monday of current week: //What day is today? $today = strftime("%u", $inDate); //"$today" is now 1-7 (Mon. - Sun.). //If "$today" is greater than 1, we want the Unix timestamp for 1: if ($today > 1) { //adjust time to get to Monday's timestamp $todayStamp = nightStartTimeStamp($inDate); //Unix timestamp for this week starting Monday: $currentWeekStartDay = $todayStamp - (($today - 1) * 86400); } else { //It's Monday, so Unix timestamp for today: $todayStamp = nightStartTimeStamp($inDate); $currentWeekStartDay = $todayStamp; } //difference between current week and seed week in weeks: $weekDifference = ($currentWeekStartDay - $seedTime)/604800.0; //floor() doesn't seem to be able to work and play well with others here: $weekDifference = substr($weekDifference, 0, 1); //create weekBlock var: $weekBlock = 0; if ($weekDifference % 2 == 0) { //Weekblock 1 $weekBlock = 1; } else { //difference in number of weeks is odd, so we're using weekblock 2 $weekBlock = 2; } //workblock is figured out; let's get our "weekstart" back on track $currentWeekStartDay -= 43200; //abstract YYYY-MM-DD from timestamp of starting monday date of work week $startDay = strftime("%e", $currentWeekStartDay); $startMonth = date("n", $currentWeekStartDay); $startYear = strftime("%Y", $currentWeekStartDay); //get current work week dates $monday = mktime(0, 0, 0, $startMonth, $startDay, $startYear); $tuesday = mktime(24, 0, 0, $startMonth, $startDay, $startYear); $wednesday = mktime(48, 0, 0, $startMonth, $startDay, $startYear); $thursday = mktime(72, 0, 0, $startMonth, $startDay, $startYear); $friday = mktime(96, 0, 0, $startMonth, $startDay, $startYear); $saturday = mktime(120, 0, 0, $startMonth, $startDay, $startYear); $sunday = mktime(144, 0, 0, $startMonth, $startDay, $startYear); //SQUAD ROTATION (FIXED) //Week 1: Mon: A / Tues: A / Wed: B / Thurs: B / Fri: A / Sat: A / Sun: A //Week 2: Mon: B / Tues: B / Wed: A / Thurs: A / Fri: B / Sat: B / Sun: B if($weekBlock == 1) $weekRotation = array($monday=>'A', $tuesday=>'A', $wednesday=>'B', $thursday=>'B', $friday=>'A', $saturday=>'A', $sunday=>'A'); if($weekBlock == 2) $weekRotation = array($monday=>'B', $tuesday=>'B', $wednesday=>'A', $thursday=>'A', $friday=>'B', $saturday=>'B', $sunday=>'B'); $workingSquad = null; foreach($weekRotation as $date=>$squad) { if($date == $inDate) $workingSquad = $squad; } if($workingSquad != null) return $workingSquad; }//end getSquadRotation() function ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1bC2f
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL_BY_NAME                                       'getSquadRotation'
          1        SEND_VAL_EX                                              '2014-01-17'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   96     4      > RETURN                                                   1

Function getsquadrotation:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 46
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 66
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 148, Position 2 = 156
Branch analysis from position: 148
2 jumps found. (Code = 43) Position 1 = 158, Position 2 = 166
Branch analysis from position: 158
2 jumps found. (Code = 77) Position 1 = 168, Position 2 = 174
Branch analysis from position: 168
2 jumps found. (Code = 78) Position 1 = 169, Position 2 = 174
Branch analysis from position: 169
2 jumps found. (Code = 43) Position 1 = 172, Position 2 = 173
Branch analysis from position: 172
1 jumps found. (Code = 42) Position 1 = 168
Branch analysis from position: 168
Branch analysis from position: 173
Branch analysis from position: 174
2 jumps found. (Code = 43) Position 1 = 177, Position 2 = 178
Branch analysis from position: 177
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 178
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 174
Branch analysis from position: 166
Branch analysis from position: 156
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 148, Position 2 = 156
Branch analysis from position: 148
Branch analysis from position: 156
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 66
Branch analysis from position: 64
Branch analysis from position: 66
filename:       /in/1bC2f
function name:  getSquadRotation
number of ops:  179
compiled vars:  !0 = $inDate, !1 = $content, !2 = $seedTime, !3 = $today, !4 = $todayStamp, !5 = $currentWeekStartDay, !6 = $weekDifference, !7 = $weekBlock, !8 = $startDay, !9 = $startMonth, !10 = $startYear, !11 = $monday, !12 = $tuesday, !13 = $wednesday, !14 = $thursday, !15 = $friday, !16 = $saturday, !17 = $sunday, !18 = $weekRotation, !19 = $workingSquad, !20 = $squad, !21 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    9     1        INIT_FCALL                                               'date_default_timezone_set'
          2        SEND_VAL                                                 'America%2FNew_York'
          3        DO_ICALL                                                 
   12     4        INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '-'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $23     
          8        ASSIGN                                                   !1, $23
   13     9        INIT_FCALL                                               'mktime'
         10        SEND_VAL                                                 0
         11        SEND_VAL                                                 0
         12        SEND_VAL                                                 0
         13        FETCH_DIM_R                                      ~25     !1, 1
         14        SEND_VAL                                                 ~25
         15        FETCH_DIM_R                                      ~26     !1, 2
         16        SEND_VAL                                                 ~26
         17        FETCH_DIM_R                                      ~27     !1, 0
         18        SEND_VAL                                                 ~27
         19        DO_ICALL                                         $28     
         20        ASSIGN                                                   !0, $28
   15    21        INIT_FCALL                                               'mktime'
         22        SEND_VAL                                                 0
         23        SEND_VAL                                                 0
         24        SEND_VAL                                                 0
         25        SEND_VAL                                                 12
         26        SEND_VAL                                                 23
         27        SEND_VAL                                                 2013
         28        DO_ICALL                                         $30     
         29        ASSIGN                                                   !2, $30
   23    30        INIT_FCALL                                               'strftime'
         31        SEND_VAL                                                 '%25u'
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $32     
         34        ASSIGN                                                   !3, $32
   27    35        IS_SMALLER                                               1, !3
         36      > JMPZ                                                     ~34, ->46
   29    37    >   INIT_FCALL_BY_NAME                                       'nightStartTimeStamp'
         38        SEND_VAR_EX                                              !0
         39        DO_FCALL                                      0  $35     
         40        ASSIGN                                                   !4, $35
   32    41        SUB                                              ~37     !3, 1
         42        MUL                                              ~38     ~37, 86400
         43        SUB                                              ~39     !4, ~38
         44        ASSIGN                                                   !5, ~39
         45      > JMP                                                      ->51
   36    46    >   INIT_FCALL_BY_NAME                                       'nightStartTimeStamp'
         47        SEND_VAR_EX                                              !0
         48        DO_FCALL                                      0  $41     
         49        ASSIGN                                                   !4, $41
   37    50        ASSIGN                                                   !5, !4
   41    51    >   SUB                                              ~44     !5, !2
         52        DIV                                              ~45     ~44, 604800
         53        ASSIGN                                                   !6, ~45
   44    54        INIT_FCALL                                               'substr'
         55        SEND_VAR                                                 !6
         56        SEND_VAL                                                 0
         57        SEND_VAL                                                 1
         58        DO_ICALL                                         $47     
         59        ASSIGN                                                   !6, $47
   47    60        ASSIGN                                                   !7, 0
   49    61        MOD                                              ~50     !6, 2
         62        IS_EQUAL                                                 ~50, 0
         63      > JMPZ                                                     ~51, ->66
   51    64    >   ASSIGN                                                   !7, 1
         65      > JMP                                                      ->67
   54    66    >   ASSIGN                                                   !7, 2
   58    67    >   ASSIGN_OP                                     2          !5, 43200
   61    68        INIT_FCALL                                               'strftime'
         69        SEND_VAL                                                 '%25e'
         70        SEND_VAR                                                 !5
         71        DO_ICALL                                         $55     
         72        ASSIGN                                                   !8, $55
   62    73        INIT_FCALL                                               'date'
         74        SEND_VAL                                                 'n'
         75        SEND_VAR                                                 !5
         76        DO_ICALL                                         $57     
         77        ASSIGN                                                   !9, $57
   63    78        INIT_FCALL                                               'strftime'
         79        SEND_VAL                                                 '%25Y'
         80        SEND_VAR                                                 !5
         81        DO_ICALL                                         $59     
         82        ASSIGN                                                   !10, $59
   66    83        INIT_FCALL                                               'mktime'
         84        SEND_VAL                                                 0
         85        SEND_VAL                                                 0
         86        SEND_VAL                                                 0
         87        SEND_VAR                                                 !9
         88        SEND_VAR                                                 !8
         89        SEND_VAR                                                 !10
         90        DO_ICALL                                         $61     
         91        ASSIGN                                                   !11, $61
   67    92        INIT_FCALL                                               'mktime'
         93        SEND_VAL                                                 24
         94        SEND_VAL                                                 0
         95        SEND_VAL                                                 0
         96        SEND_VAR                                                 !9
         97        SEND_VAR                                                 !8
         98        SEND_VAR                                                 !10
         99        DO_ICALL                                         $63     
        100        ASSIGN                                                   !12, $63
   68   101        INIT_FCALL                                               'mktime'
        102        SEND_VAL                                                 48
        103        SEND_VAL                                                 0
        104        SEND_VAL                                                 0
        105        SEND_VAR                                                 !9
        106        SEND_VAR                                                 !8
        107        SEND_VAR                                                 !10
        108        DO_ICALL                                         $65     
        109        ASSIGN                                                   !13, $65
   69   110        INIT_FCALL                                               'mktime'
        111        SEND_VAL                                                 72
        112        SEND_VAL                                                 0
        113        SEND_VAL                                                 0
        114        SEND_VAR                                                 !9
        115        SEND_VAR                                                 !8
        116        SEND_VAR                                                 !10
        117        DO_ICALL                                         $67     
        118        ASSIGN                                                   !14, $67
   70   119        INIT_FCALL                                               'mktime'
        120        SEND_VAL                                                 96
        121        SEND_VAL                                                 0
        122        SEND_VAL                                                 0
        123        SEND_VAR                                                 !9
        124        SEND_VAR                                                 !8
        125        SEND_VAR                                                 !10
        126        DO_ICALL                                         $69     
        127        ASSIGN                                                   !15, $69
   71   128        INIT_FCALL                                               'mktime'
        129        SEND_VAL                                                 120
        130        SEND_VAL                                                 0
        131        SEND_VAL                                                 0
        132        SEND_VAR                                                 !9
        133        SEND_VAR                                                 !8
        134        SEND_VAR                                                 !10
        135        DO_ICALL                                         $71     
        136        ASSIGN                                                   !16, $71
   72   137        INIT_FCALL                                               'mktime'
        138        SEND_VAL                                                 144
        139        SEND_VAL                                                 0
        140        SEND_VAL                                                 0
        141        SEND_VAR                                                 !9
        142        SEND_VAR                                                 !8
        143        SEND_VAR                                                 !10
        144        DO_ICALL                                         $73     
        145        ASSIGN                                                   !17, $73
   77   146        IS_EQUAL                                                 !7, 1
        147      > JMPZ                                                     ~75, ->156
   78   148    >   INIT_ARRAY                                       ~76     'A', !11
        149        ADD_ARRAY_ELEMENT                                ~76     'A', !12
        150        ADD_ARRAY_ELEMENT                                ~76     'B', !13
        151        ADD_ARRAY_ELEMENT                                ~76     'B', !14
        152        ADD_ARRAY_ELEMENT                                ~76     'A', !15
        153        ADD_ARRAY_ELEMENT                                ~76     'A', !16
        154        ADD_ARRAY_ELEMENT                                ~76     'A', !17
        155        ASSIGN                                                   !18, ~76
   79   156    >   IS_EQUAL                                                 !7, 2
        157      > JMPZ                                                     ~78, ->166
   80   158    >   INIT_ARRAY                                       ~79     'B', !11
        159        ADD_ARRAY_ELEMENT                                ~79     'B', !12
        160        ADD_ARRAY_ELEMENT                                ~79     'A', !13
        161        ADD_ARRAY_ELEMENT                                ~79     'A', !14
        162        ADD_ARRAY_ELEMENT                                ~79     'B', !15
        163        ADD_ARRAY_ELEMENT                                ~79     'B', !16
        164        ADD_ARRAY_ELEMENT                                ~79     'B', !17
        165        ASSIGN                                                   !18, ~79
   82   166    >   ASSIGN                                                   !19, null
   83   167      > FE_RESET_R                                       $82     !18, ->174
        168    > > FE_FETCH_R                                       ~83     $82, !20, ->174
        169    >   ASSIGN                                                   !21, ~83
   85   170        IS_EQUAL                                                 !21, !0
        171      > JMPZ                                                     ~85, ->173
   86   172    >   ASSIGN                                                   !19, !20
   83   173    > > JMP                                                      ->168
        174    >   FE_FREE                                                  $82
   89   175        IS_NOT_EQUAL                                             !19, null
        176      > JMPZ                                                     ~87, ->178
   90   177    > > RETURN                                                   !19
   91   178    > > RETURN                                                   null

End of function getsquadrotation

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.38 ms | 1412 KiB | 25 Q