3v4l.org

run code in 500+ PHP versions simultaneously
<?php /** * @link http://stackoverflow.com/questions/26453510/datetimezone-and-utc-offset-for-standard-and-daylight-times */ /** * @param $seconds * * @return string +\d\d\d\d / -\d\d\d\d */ function format_offset($seconds) { $minutes = (int) ($seconds / 60); $hours = (int) ($minutes / 60); $leftover = abs($minutes - $hours * 60); return sprintf("%+03d%02d", $hours, $leftover); } $zones = array('EDT', 'EST'); foreach ($zones as $zone) { // get offset $timezone = new DateTimeZone($zone); $offset = $timezone->getOffset(new DateTime(null, $timezone)); printf("%s (%s) %s\n", $zone, $timezone->getName(), format_offset($offset)); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 27
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 27
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/XuhI6
function name:  (null)
number of ops:  29
compiled vars:  !0 = $zones, !1 = $zone, !2 = $timezone, !3 = $offset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                       !0, <array>
   20     1      > FE_RESET_R                                           $5      !0, ->27
          2    > > FE_FETCH_R                                                   $5, !1, ->27
   22     3    >   NEW                                                  $6      'DateTimeZone'
          4        SEND_VAR_EX                                                  !1
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !2, $6
   23     7        INIT_METHOD_CALL                                             !2, 'getOffset'
          8        NEW                                                  $9      'DateTime'
          9        SEND_VAL_EX                                                  null
         10        SEND_VAR_EX                                                  !2
         11        DO_FCALL                                          0          
         12        SEND_VAR_NO_REF_EX                                           $9
         13        DO_FCALL                                          0  $11     
         14        ASSIGN                                                       !3, $11
   25    15        INIT_FCALL                                                   'printf'
         16        SEND_VAL                                                     '%25s+%28%25s%29+%25s%0A'
         17        SEND_VAR                                                     !1
         18        INIT_METHOD_CALL                                             !2, 'getName'
         19        DO_FCALL                                          0  $13     
         20        SEND_VAR                                                     $13
         21        INIT_FCALL                                                   'format_offset'
         22        SEND_VAR                                                     !3
         23        DO_FCALL                                          0  $14     
         24        SEND_VAR                                                     $14
         25        DO_ICALL                                                     
   20    26      > JMP                                                          ->2
         27    >   FE_FREE                                                      $5
   26    28      > RETURN                                                       1

Function format_offset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XuhI6
function name:  format_offset
number of ops:  20
compiled vars:  !0 = $seconds, !1 = $minutes, !2 = $hours, !3 = $leftover
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
   12     1        DIV                                                  ~4      !0, 60
          2        CAST                                              4  ~5      ~4
          3        ASSIGN                                                       !1, ~5
   13     4        DIV                                                  ~7      !1, 60
          5        CAST                                              4  ~8      ~7
          6        ASSIGN                                                       !2, ~8
   14     7        INIT_FCALL                                                   'abs'
          8        MUL                                                  ~10     !2, 60
          9        SUB                                                  ~11     !1, ~10
         10        SEND_VAL                                                     ~11
         11        DO_ICALL                                             $12     
         12        ASSIGN                                                       !3, $12
   15    13        INIT_FCALL                                                   'sprintf'
         14        SEND_VAL                                                     '%25%2B03d%2502d'
         15        SEND_VAR                                                     !2
         16        SEND_VAR                                                     !3
         17        DO_ICALL                                             $14     
         18      > RETURN                                                       $14
   16    19*     > RETURN                                                       null

End of function format_offset

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.95 ms | 2842 KiB | 17 Q