3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_date_range_from_time_period($str_time_period,$str_base_time = NULL) { if (!empty($str_base_time)) { $int_current_time = $str_base_time; } else { $int_current_time = time(); } $arr_parameter_range = array(); if ($str_time_period == "yesterday") { $int_start_time = mktime(0,0,0,date("m",$int_current_time),date("d",$int_current_time)-1,date("Y",$int_current_time)); $int_end_time = mktime(23,59,59,date("m",$int_current_time),date("d",$int_current_time)-1,date("Y",$int_current_time)); } else if ($str_time_period == "last_week") { // trickiest - we start by finding the current day of the week which we can use as an offset $int_current_day_of_week = date("N",$int_current_time); $int_week_start_offset = 6 + $int_current_day_of_week; $int_week_end_offset = $int_week_start_offset - 6; $int_start_time = mktime(0,0,0,date("m",$int_current_time),date("d",$int_current_time)-$int_week_start_offset,date("Y",$int_current_time)); $int_end_time = mktime(23,59,59,date("m",$int_current_time),date("d",$int_current_time)-$int_week_end_offset,date("Y",$int_current_time)); } else if ($str_time_period == "last_month") { $int_start_time = mktime(0,0,0,date("m",$int_current_time)-1,1,date("Y",$int_current_time)); $int_end_time = mktime(23,59,59,date("m",$int_current_time),0,date("Y",$int_current_time)); // 0 date should make it return the last day of the previous month } else { return FALSE; } $arr_parameter_range['start_timestamp'] = $int_start_time; $arr_parameter_range['end_timestamp'] = $int_end_time; $arr_parameter_range['start_iso'] = date("Y-m-d H:i:s",$int_start_time); $arr_parameter_range['end_iso'] = date("Y-m-d H:i:s",$int_end_time); return $arr_parameter_range; } function convertUnixTimeBetweenTimezones($vUnixTime,$vOriginalTimezone,$vDesiredTimezone) { if ($vOriginalTimezone == $vDesiredTimezone) { // no timezone shifting required return $vUnixTime; } // set default to desired timezone $vCurrentTimezone = date_default_timezone_get(); date_default_timezone_set($vDesiredTimezone); $oBaseTimeZone = new DateTimeZone($vOriginalTimezone); // user time zone $oCurrentTimeZone = new DateTimeZone($vDesiredTimezone); $vIsoTime = date("Y-m-d H:i:s",$vUnixTime); $oBaseTime = new DateTime($vIsoTime,$oBaseTimeZone); $oBaseTime->setTimezone($oCurrentTimeZone); $vTimeStamp = $oBaseTime->getTimestamp(); date_default_timezone_set($vCurrentTimezone); return $vTimeStamp; } $arr_data = get_date_range_from_time_period('yesterday',strtotime("2014-11-01 00:00:00")); print_r($arr_data); echo convertUnixTimeBetweenTimezones($arr_data['start_timestamp'],"EST","UTC"); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6E0p9
function name:  (null)
number of ops:  19
compiled vars:  !0 = $arr_data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   INIT_FCALL                                               'get_date_range_from_time_period'
          1        SEND_VAL                                                 'yesterday'
          2        INIT_FCALL                                               'strtotime'
          3        SEND_VAL                                                 '2014-11-01+00%3A00%3A00'
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        DO_FCALL                                      0  $2      
          7        ASSIGN                                                   !0, $2
   79     8        INIT_FCALL                                               'print_r'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
   80    11        INIT_FCALL                                               'convertunixtimebetweentimezones'
         12        FETCH_DIM_R                                      ~5      !0, 'start_timestamp'
         13        SEND_VAL                                                 ~5
         14        SEND_VAL                                                 'EST'
         15        SEND_VAL                                                 'UTC'
         16        DO_FCALL                                      0  $6      
         17        ECHO                                                     $6
   82    18      > RETURN                                                   1

Function get_date_range_from_time_period:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 58
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 153
Branch analysis from position: 153
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 114
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 153
Branch analysis from position: 153
Branch analysis from position: 114
2 jumps found. (Code = 43) Position 1 = 116, Position 2 = 152
Branch analysis from position: 116
1 jumps found. (Code = 42) Position 1 = 153
Branch analysis from position: 153
Branch analysis from position: 152
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 58
Branch analysis from position: 13
Branch analysis from position: 58
filename:       /in/6E0p9
function name:  get_date_range_from_time_period
number of ops:  171
compiled vars:  !0 = $str_time_period, !1 = $str_base_time, !2 = $int_current_time, !3 = $arr_parameter_range, !4 = $int_start_time, !5 = $int_end_time, !6 = $int_current_day_of_week, !7 = $int_week_start_offset, !8 = $int_week_end_offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    5     2        ISSET_ISEMPTY_CV                                 ~9      !1
          3        BOOL_NOT                                         ~10     ~9
          4      > JMPZ                                                     ~10, ->7
    7     5    >   ASSIGN                                                   !2, !1
          6      > JMP                                                      ->10
   11     7    >   INIT_FCALL                                               'time'
          8        DO_ICALL                                         $12     
          9        ASSIGN                                                   !2, $12
   14    10    >   ASSIGN                                                   !3, <array>
   16    11        IS_EQUAL                                                 !0, 'yesterday'
         12      > JMPZ                                                     ~15, ->58
   18    13    >   INIT_FCALL                                               'mktime'
         14        SEND_VAL                                                 0
         15        SEND_VAL                                                 0
         16        SEND_VAL                                                 0
         17        INIT_FCALL                                               'date'
         18        SEND_VAL                                                 'm'
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $16     
         21        SEND_VAR                                                 $16
         22        INIT_FCALL                                               'date'
         23        SEND_VAL                                                 'd'
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                         $17     
         26        SUB                                              ~18     $17, 1
         27        SEND_VAL                                                 ~18
         28        INIT_FCALL                                               'date'
         29        SEND_VAL                                                 'Y'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                         $19     
         32        SEND_VAR                                                 $19
         33        DO_ICALL                                         $20     
         34        ASSIGN                                                   !4, $20
   19    35        INIT_FCALL                                               'mktime'
         36        SEND_VAL                                                 23
         37        SEND_VAL                                                 59
         38        SEND_VAL                                                 59
         39        INIT_FCALL                                               'date'
         40        SEND_VAL                                                 'm'
         41        SEND_VAR                                                 !2
         42        DO_ICALL                                         $22     
         43        SEND_VAR                                                 $22
         44        INIT_FCALL                                               'date'
         45        SEND_VAL                                                 'd'
         46        SEND_VAR                                                 !2
         47        DO_ICALL                                         $23     
         48        SUB                                              ~24     $23, 1
         49        SEND_VAL                                                 ~24
         50        INIT_FCALL                                               'date'
         51        SEND_VAL                                                 'Y'
         52        SEND_VAR                                                 !2
         53        DO_ICALL                                         $25     
         54        SEND_VAR                                                 $25
         55        DO_ICALL                                         $26     
         56        ASSIGN                                                   !5, $26
         57      > JMP                                                      ->153
   21    58    >   IS_EQUAL                                                 !0, 'last_week'
         59      > JMPZ                                                     ~28, ->114
   24    60    >   INIT_FCALL                                               'date'
         61        SEND_VAL                                                 'N'
         62        SEND_VAR                                                 !2
         63        DO_ICALL                                         $29     
         64        ASSIGN                                                   !6, $29
   25    65        ADD                                              ~31     6, !6
         66        ASSIGN                                                   !7, ~31
   26    67        SUB                                              ~33     !7, 6
         68        ASSIGN                                                   !8, ~33
   27    69        INIT_FCALL                                               'mktime'
         70        SEND_VAL                                                 0
         71        SEND_VAL                                                 0
         72        SEND_VAL                                                 0
         73        INIT_FCALL                                               'date'
         74        SEND_VAL                                                 'm'
         75        SEND_VAR                                                 !2
         76        DO_ICALL                                         $35     
         77        SEND_VAR                                                 $35
         78        INIT_FCALL                                               'date'
         79        SEND_VAL                                                 'd'
         80        SEND_VAR                                                 !2
         81        DO_ICALL                                         $36     
         82        SUB                                              ~37     $36, !7
         83        SEND_VAL                                                 ~37
         84        INIT_FCALL                                               'date'
         85        SEND_VAL                                                 'Y'
         86        SEND_VAR                                                 !2
         87        DO_ICALL                                         $38     
         88        SEND_VAR                                                 $38
         89        DO_ICALL                                         $39     
         90        ASSIGN                                                   !4, $39
   28    91        INIT_FCALL                                               'mktime'
         92        SEND_VAL                                                 23
         93        SEND_VAL                                                 59
         94        SEND_VAL                                                 59
         95        INIT_FCALL                                               'date'
         96        SEND_VAL                                                 'm'
         97        SEND_VAR                                                 !2
         98        DO_ICALL                                         $41     
         99        SEND_VAR                                                 $41
        100        INIT_FCALL                                               'date'
        101        SEND_VAL                                                 'd'
        102        SEND_VAR                                                 !2
        103        DO_ICALL                                         $42     
        104        SUB                                              ~43     $42, !8
        105        SEND_VAL                                                 ~43
        106        INIT_FCALL                                               'date'
        107        SEND_VAL                                                 'Y'
        108        SEND_VAR                                                 !2
        109        DO_ICALL                                         $44     
        110        SEND_VAR                                                 $44
        111        DO_ICALL                                         $45     
        112        ASSIGN                                                   !5, $45
        113      > JMP                                                      ->153
   30   114    >   IS_EQUAL                                                 !0, 'last_month'
        115      > JMPZ                                                     ~47, ->152
   32   116    >   INIT_FCALL                                               'mktime'
        117        SEND_VAL                                                 0
        118        SEND_VAL                                                 0
        119        SEND_VAL                                                 0
        120        INIT_FCALL                                               'date'
        121        SEND_VAL                                                 'm'
        122        SEND_VAR                                                 !2
        123        DO_ICALL                                         $48     
        124        SUB                                              ~49     $48, 1
        125        SEND_VAL                                                 ~49
        126        SEND_VAL                                                 1
        127        INIT_FCALL                                               'date'
        128        SEND_VAL                                                 'Y'
        129        SEND_VAR                                                 !2
        130        DO_ICALL                                         $50     
        131        SEND_VAR                                                 $50
        132        DO_ICALL                                         $51     
        133        ASSIGN                                                   !4, $51
   33   134        INIT_FCALL                                               'mktime'
        135        SEND_VAL                                                 23
        136        SEND_VAL                                                 59
        137        SEND_VAL                                                 59
        138        INIT_FCALL                                               'date'
        139        SEND_VAL                                                 'm'
        140        SEND_VAR                                                 !2
        141        DO_ICALL                                         $53     
        142        SEND_VAR                                                 $53
        143        SEND_VAL                                                 0
        144        INIT_FCALL                                               'date'
        145        SEND_VAL                                                 'Y'
        146        SEND_VAR                                                 !2
        147        DO_ICALL                                         $54     
        148        SEND_VAR                                                 $54
        149        DO_ICALL                                         $55     
        150        ASSIGN                                                   !5, $55
        151      > JMP                                                      ->153
   37   152    > > RETURN                                                   <false>
   40   153    >   ASSIGN_DIM                                               !3, 'start_timestamp'
        154        OP_DATA                                                  !4
   41   155        ASSIGN_DIM                                               !3, 'end_timestamp'
        156        OP_DATA                                                  !5
   42   157        INIT_FCALL                                               'date'
        158        SEND_VAL                                                 'Y-m-d+H%3Ai%3As'
        159        SEND_VAR                                                 !4
        160        DO_ICALL                                         $60     
        161        ASSIGN_DIM                                               !3, 'start_iso'
        162        OP_DATA                                                  $60
   43   163        INIT_FCALL                                               'date'
        164        SEND_VAL                                                 'Y-m-d+H%3Ai%3As'
        165        SEND_VAR                                                 !5
        166        DO_ICALL                                         $62     
        167        ASSIGN_DIM                                               !3, 'end_iso'
        168        OP_DATA                                                  $62
   45   169      > RETURN                                                   !3
   46   170*     > RETURN                                                   null

End of function get_date_range_from_time_period

Function convertunixtimebetweentimezones:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6E0p9
function name:  convertUnixTimeBetweenTimezones
number of ops:  41
compiled vars:  !0 = $vUnixTime, !1 = $vOriginalTimezone, !2 = $vDesiredTimezone, !3 = $vCurrentTimezone, !4 = $oBaseTimeZone, !5 = $oCurrentTimeZone, !6 = $vIsoTime, !7 = $oBaseTime, !8 = $vTimeStamp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   50     3        IS_EQUAL                                                 !1, !2
          4      > JMPZ                                                     ~9, ->6
   53     5    > > RETURN                                                   !0
   57     6    >   INIT_FCALL                                               'date_default_timezone_get'
          7        DO_ICALL                                         $10     
          8        ASSIGN                                                   !3, $10
   58     9        INIT_FCALL                                               'date_default_timezone_set'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                                 
   60    12        NEW                                              $13     'DateTimeZone'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !4, $13
   62    16        NEW                                              $16     'DateTimeZone'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !5, $16
   64    20        INIT_FCALL                                               'date'
         21        SEND_VAL                                                 'Y-m-d+H%3Ai%3As'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $19     
         24        ASSIGN                                                   !6, $19
   65    25        NEW                                              $21     'DateTime'
         26        SEND_VAR_EX                                              !6
         27        SEND_VAR_EX                                              !4
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !7, $21
   66    30        INIT_METHOD_CALL                                         !7, 'setTimezone'
         31        SEND_VAR_EX                                              !5
         32        DO_FCALL                                      0          
   68    33        INIT_METHOD_CALL                                         !7, 'getTimestamp'
         34        DO_FCALL                                      0  $25     
         35        ASSIGN                                                   !8, $25
   70    36        INIT_FCALL                                               'date_default_timezone_set'
         37        SEND_VAR                                                 !3
         38        DO_ICALL                                                 
   72    39      > RETURN                                                   !8
   73    40*     > RETURN                                                   null

End of function convertunixtimebetweentimezones

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.93 ms | 1419 KiB | 29 Q