3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "events": [{ "event_site_url": "https://www.yelp.com/events/london-the-european-information-security-summit-2017", "id": "london-the-european-information-security-summit-2017", "latitude": 51.5009690970451, "longitude": -0.119283199310303, "name": "The European Information Security Summit 2017", "time_start": "2018-02-21 17:00", "time_end": "2018-02-23 02:30" }] }'; $data = json_decode($json); $event = $data->events[0]; function get_nearest_timezone($cur_lat, $cur_long, $country_code = '') { $timezone_ids = ($country_code) ? DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code) : DateTimeZone::listIdentifiers(); if($timezone_ids && is_array($timezone_ids) && isset($timezone_ids[0])) { $time_zone = ''; $tz_distance = 0; //only one identifier? if (count($timezone_ids) == 1) { $time_zone = $timezone_ids[0]; } else { foreach($timezone_ids as $timezone_id) { $timezone = new DateTimeZone($timezone_id); $location = $timezone->getLocation(); $tz_lat = $location['latitude']; $tz_long = $location['longitude']; $theta = $cur_long - $tz_long; $distance = (sin(deg2rad($cur_lat)) * sin(deg2rad($tz_lat))) + (cos(deg2rad($cur_lat)) * cos(deg2rad($tz_lat)) * cos(deg2rad($theta))); $distance = acos($distance); $distance = abs(rad2deg($distance)); // echo '<br />'.$timezone_id.' '.$distance; if (!$time_zone || $tz_distance > $distance) { $time_zone = $timezone_id; $tz_distance = $distance; } } } return $time_zone; } return 'unknown'; } function getClosestTimezone($lat, $lng) { $diffs = array(); foreach(DateTimeZone::listIdentifiers() as $timezoneID) { $timezone = new DateTimeZone($timezoneID); $location = $timezone->getLocation(); $tLat = $location['latitude']; $tLng = $location['longitude']; $diffLat = abs($lat - $tLat); $diffLng = abs($lng - $tLng); $diff = $diffLat + $diffLng; $diffs[$timezoneID] = $diff; } //asort($diffs); $timezone = array_keys($diffs, min($diffs)); return $timezone[0]; } //timezone from co-ordinate $tz = getClosestTimezone($event->latitude, $event->longitude); //From: Wednesday, Feb 21, 9:00 am $date = DateTime::createFromFormat('Y-m-d H:i', $event->time_start, new DateTimeZone($tz)); echo 'From: '.$date->format('l, M j, g:m a') . "\n"; //To: Thursday, Feb 22, 6:30 pm $date = DateTime::createFromFormat('Y-m-d H:i', $event->time_end, new DateTimeZone($tz)); echo 'From: '.$date->format('l, M j, g:m a') . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qsdm0
function name:  (null)
number of ops:  48
compiled vars:  !0 = $json, !1 = $data, !2 = $event, !3 = $tz, !4 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%7B%0A%22events%22%3A+%5B%7B%0A++++%22event_site_url%22%3A+%22https%3A%2F%2Fwww.yelp.com%2Fevents%2Flondon-the-european-information-security-summit-2017%22%2C%0A++++%22id%22%3A+%22london-the-european-information-security-summit-2017%22%2C%0A++++%22latitude%22%3A+51.5009690970451%2C%0A++++%22longitude%22%3A+-0.119283199310303%2C%0A++++%22name%22%3A+%22The+European+Information+Security+Summit+2017%22%2C%0A++++%22time_start%22%3A+%222018-02-21+17%3A00%22%2C%0A++++%22time_end%22%3A+%222018-02-23+02%3A30%22%0A%7D%5D%0A%7D'
   14     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
   16     5        FETCH_OBJ_R                                      ~8      !1, 'events'
          6        FETCH_DIM_R                                      ~9      ~8, 0
          7        ASSIGN                                                   !2, ~9
   81     8        INIT_FCALL                                               'getclosesttimezone'
          9        FETCH_OBJ_R                                      ~11     !2, 'latitude'
         10        SEND_VAL                                                 ~11
         11        FETCH_OBJ_R                                      ~12     !2, 'longitude'
         12        SEND_VAL                                                 ~12
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   84    15        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         16        SEND_VAL                                                 'Y-m-d+H%3Ai'
         17        FETCH_OBJ_R                                      ~15     !2, 'time_start'
         18        SEND_VAL                                                 ~15
         19        NEW                                              $16     'DateTimeZone'
         20        SEND_VAR_EX                                              !3
         21        DO_FCALL                                      0          
         22        SEND_VAR                                                 $16
         23        DO_FCALL                                      0  $18     
         24        ASSIGN                                                   !4, $18
   85    25        INIT_METHOD_CALL                                         !4, 'format'
         26        SEND_VAL_EX                                              'l%2C+M+j%2C+g%3Am+a'
         27        DO_FCALL                                      0  $20     
         28        CONCAT                                           ~21     'From%3A+', $20
         29        CONCAT                                           ~22     ~21, '%0A'
         30        ECHO                                                     ~22
   88    31        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         32        SEND_VAL                                                 'Y-m-d+H%3Ai'
         33        FETCH_OBJ_R                                      ~23     !2, 'time_end'
         34        SEND_VAL                                                 ~23
         35        NEW                                              $24     'DateTimeZone'
         36        SEND_VAR_EX                                              !3
         37        DO_FCALL                                      0          
         38        SEND_VAR                                                 $24
         39        DO_FCALL                                      0  $26     
         40        ASSIGN                                                   !4, $26
   89    41        INIT_METHOD_CALL                                         !4, 'format'
         42        SEND_VAL_EX                                              'l%2C+M+j%2C+g%3Am+a'
         43        DO_FCALL                                      0  $28     
         44        CONCAT                                           ~29     'From%3A+', $28
         45        CONCAT                                           ~30     ~29, '%0A'
         46        ECHO                                                     ~30
         47      > RETURN                                                   1

Function get_nearest_timezone:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 100
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 98
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 98
Branch analysis from position: 31
2 jumps found. (Code = 47) Position 1 = 92, Position 2 = 94
Branch analysis from position: 92
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 97
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 97
Branch analysis from position: 94
Branch analysis from position: 98
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 98
Branch analysis from position: 100
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 17
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
Branch analysis from position: 17
filename:       /in/qsdm0
function name:  get_nearest_timezone
number of ops:  102
compiled vars:  !0 = $cur_lat, !1 = $cur_long, !2 = $country_code, !3 = $timezone_ids, !4 = $time_zone, !5 = $tz_distance, !6 = $timezone_id, !7 = $timezone, !8 = $location, !9 = $tz_lat, !10 = $tz_long, !11 = $theta, !12 = $distance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      ''
   19     3      > JMPZ                                                     !2, ->10
          4    >   INIT_STATIC_METHOD_CALL                                  'DateTimeZone', 'listIdentifiers'
          5        SEND_VAL                                                 4096
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0  $13     
          8        QM_ASSIGN                                        ~14     $13
          9      > JMP                                                      ->13
   20    10    >   INIT_STATIC_METHOD_CALL                                  'DateTimeZone', 'listIdentifiers'
         11        DO_FCALL                                      0  $15     
         12        QM_ASSIGN                                        ~14     $15
   19    13    >   ASSIGN                                                   !3, ~14
   22    14      > JMPZ_EX                                          ~17     !3, ->17
         15    >   TYPE_CHECK                                  128  ~18     !3
         16        BOOL                                             ~17     ~18
         17    > > JMPZ_EX                                          ~17     ~17, ->20
         18    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~19     !3, 0
         19        BOOL                                             ~17     ~19
         20    > > JMPZ                                                     ~17, ->100
   24    21    >   ASSIGN                                                   !4, ''
   25    22        ASSIGN                                                   !5, 0
   28    23        COUNT                                            ~22     !3
         24        IS_EQUAL                                                 ~22, 1
         25      > JMPZ                                                     ~23, ->29
   29    26    >   FETCH_DIM_R                                      ~24     !3, 0
         27        ASSIGN                                                   !4, ~24
         28      > JMP                                                      ->99
   32    29    > > FE_RESET_R                                       $26     !3, ->98
         30    > > FE_FETCH_R                                               $26, !6, ->98
   33    31    >   NEW                                              $27     'DateTimeZone'
         32        SEND_VAR_EX                                              !6
         33        DO_FCALL                                      0          
         34        ASSIGN                                                   !7, $27
   34    35        INIT_METHOD_CALL                                         !7, 'getLocation'
         36        DO_FCALL                                      0  $30     
         37        ASSIGN                                                   !8, $30
   35    38        FETCH_DIM_R                                      ~32     !8, 'latitude'
         39        ASSIGN                                                   !9, ~32
   36    40        FETCH_DIM_R                                      ~34     !8, 'longitude'
         41        ASSIGN                                                   !10, ~34
   38    42        SUB                                              ~36     !1, !10
         43        ASSIGN                                                   !11, ~36
   39    44        INIT_FCALL                                               'sin'
         45        INIT_FCALL                                               'deg2rad'
         46        SEND_VAR                                                 !0
         47        DO_ICALL                                         $38     
         48        SEND_VAR                                                 $38
         49        DO_ICALL                                         $39     
         50        INIT_FCALL                                               'sin'
         51        INIT_FCALL                                               'deg2rad'
         52        SEND_VAR                                                 !9
         53        DO_ICALL                                         $40     
         54        SEND_VAR                                                 $40
         55        DO_ICALL                                         $41     
         56        MUL                                              ~42     $39, $41
   40    57        INIT_FCALL                                               'cos'
         58        INIT_FCALL                                               'deg2rad'
         59        SEND_VAR                                                 !0
         60        DO_ICALL                                         $43     
         61        SEND_VAR                                                 $43
         62        DO_ICALL                                         $44     
         63        INIT_FCALL                                               'cos'
         64        INIT_FCALL                                               'deg2rad'
         65        SEND_VAR                                                 !9
         66        DO_ICALL                                         $45     
         67        SEND_VAR                                                 $45
         68        DO_ICALL                                         $46     
         69        MUL                                              ~47     $44, $46
         70        INIT_FCALL                                               'cos'
         71        INIT_FCALL                                               'deg2rad'
         72        SEND_VAR                                                 !11
         73        DO_ICALL                                         $48     
         74        SEND_VAR                                                 $48
         75        DO_ICALL                                         $49     
         76        MUL                                              ~50     $49, ~47
         77        ADD                                              ~51     ~42, ~50
   39    78        ASSIGN                                                   !12, ~51
   41    79        INIT_FCALL                                               'acos'
         80        SEND_VAR                                                 !12
         81        DO_ICALL                                         $53     
         82        ASSIGN                                                   !12, $53
   42    83        INIT_FCALL                                               'abs'
         84        INIT_FCALL                                               'rad2deg'
         85        SEND_VAR                                                 !12
         86        DO_ICALL                                         $55     
         87        SEND_VAR                                                 $55
         88        DO_ICALL                                         $56     
         89        ASSIGN                                                   !12, $56
   45    90        BOOL_NOT                                         ~58     !4
         91      > JMPNZ_EX                                         ~58     ~58, ->94
         92    >   IS_SMALLER                                       ~59     !12, !5
         93        BOOL                                             ~58     ~59
         94    > > JMPZ                                                     ~58, ->97
   46    95    >   ASSIGN                                                   !4, !6
   47    96        ASSIGN                                                   !5, !12
   32    97    > > JMP                                                      ->30
         98    >   FE_FREE                                                  $26
   52    99    > > RETURN                                                   !4
   54   100    > > RETURN                                                   'unknown'
   55   101*     > RETURN                                                   null

End of function get_nearest_timezone

Function getclosesttimezone:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 33
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 33
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/qsdm0
function name:  getClosestTimezone
number of ops:  45
compiled vars:  !0 = $lat, !1 = $lng, !2 = $diffs, !3 = $timezoneID, !4 = $timezone, !5 = $location, !6 = $tLat, !7 = $tLng, !8 = $diffLat, !9 = $diffLng, !10 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   59     2        ASSIGN                                                   !2, <array>
   60     3        INIT_STATIC_METHOD_CALL                                  'DateTimeZone', 'listIdentifiers'
          4        DO_FCALL                                      0  $12     
          5      > FE_RESET_R                                       $13     $12, ->33
          6    > > FE_FETCH_R                                               $13, !3, ->33
   61     7    >   NEW                                              $14     'DateTimeZone'
          8        SEND_VAR_EX                                              !3
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !4, $14
   62    11        INIT_METHOD_CALL                                         !4, 'getLocation'
         12        DO_FCALL                                      0  $17     
         13        ASSIGN                                                   !5, $17
   63    14        FETCH_DIM_R                                      ~19     !5, 'latitude'
         15        ASSIGN                                                   !6, ~19
   64    16        FETCH_DIM_R                                      ~21     !5, 'longitude'
         17        ASSIGN                                                   !7, ~21
   65    18        INIT_FCALL                                               'abs'
         19        SUB                                              ~23     !0, !6
         20        SEND_VAL                                                 ~23
         21        DO_ICALL                                         $24     
         22        ASSIGN                                                   !8, $24
   66    23        INIT_FCALL                                               'abs'
         24        SUB                                              ~26     !1, !7
         25        SEND_VAL                                                 ~26
         26        DO_ICALL                                         $27     
         27        ASSIGN                                                   !9, $27
   67    28        ADD                                              ~29     !8, !9
         29        ASSIGN                                                   !10, ~29
   68    30        ASSIGN_DIM                                               !2, !3
         31        OP_DATA                                                  !10
   60    32      > JMP                                                      ->6
         33    >   FE_FREE                                                  $13
   73    34        INIT_FCALL                                               'array_keys'
         35        SEND_VAR                                                 !2
         36        INIT_FCALL                                               'min'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $32     
         39        SEND_VAR                                                 $32
         40        DO_ICALL                                         $33     
         41        ASSIGN                                                   !4, $33
   76    42        FETCH_DIM_R                                      ~35     !4, 0
         43      > RETURN                                                   ~35
   78    44*     > RETURN                                                   null

End of function getclosesttimezone

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
189.05 ms | 1415 KiB | 32 Q