3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface DateFormatParser { /** * @param $string * * @return DateTime */ public function parse($string); } abstract class PregDateParser implements DateFormatParser { protected $pattern, $format, $mask; public function parse($string) { $string = (string)$string; $pattern = $this->pattern; $format = $this->format; $mask = $this->mask; $r = preg_match($pattern, $string, $matches); if (!$r) { throw new UnexpectedValueException('Preg Regex Pattern failed.'); } $buffer = vsprintf($mask, $matches); $result = DateTime::createFromFormat($format, $buffer); if (!$result) { throw new UnexpectedValueException(sprintf('Failed To Create from Format "%s" for "%s".', $format, $buffer)); } return $result; } } class JsonTimestampWithOffsetParser extends PregDateParser { protected $pattern = '/^\/Date\((\d{10})(\d{3})([+-]\d{4})\)\/$/'; protected $format = 'U.u.O'; protected $mask = '%2$s.%3$s.%4$s'; } $date = '/Date(1440960660000-0200)/'; $parser = new JsonTimestampWithOffsetParser; $dt = $parser->parse($date); //$dt->modify(); $timezoneShift = $dt->format('Z'); $timezoneShift = ($timezoneShift > 0) ? '+' . $timezoneShift : '-' . $timezoneShift; echo $dt->modify($timezoneShift)->format('Y-m-d H:i:s');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9QJVq
function name:  (null)
number of ops:  30
compiled vars:  !0 = $date, !1 = $parser, !2 = $dt, !3 = $timezoneShift
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   DECLARE_CLASS                                            'pregdateparser'
   38     1        DECLARE_CLASS                                            'jsontimestampwithoffsetparser', 'pregdateparser'
   45     2        ASSIGN                                                   !0, '%2FDate%281440960660000-0200%29%2F'
   46     3        NEW                                              $5      'JsonTimestampWithOffsetParser'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   47     6        INIT_METHOD_CALL                                         !1, 'parse'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !2, $8
   50    10        INIT_METHOD_CALL                                         !2, 'format'
         11        SEND_VAL_EX                                              'Z'
         12        DO_FCALL                                      0  $10     
         13        ASSIGN                                                   !3, $10
   51    14        IS_SMALLER                                               0, !3
         15      > JMPZ                                                     ~12, ->19
         16    >   CONCAT                                           ~13     '%2B', !3
         17        QM_ASSIGN                                        ~14     ~13
         18      > JMP                                                      ->21
         19    >   CONCAT                                           ~15     '-', !3
         20        QM_ASSIGN                                        ~14     ~15
         21    >   ASSIGN                                                   !3, ~14
   52    22        INIT_METHOD_CALL                                         !2, 'modify'
         23        SEND_VAR_EX                                              !3
         24        DO_FCALL                                      0  $17     
         25        INIT_METHOD_CALL                                         $17, 'format'
         26        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         27        DO_FCALL                                      0  $18     
         28        ECHO                                                     $18
         29      > RETURN                                                   1

Class DateFormatParser:
Function parse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9QJVq
function name:  parse
number of ops:  2
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function parse

End of class DateFormatParser.

Class PregDateParser:
Function parse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 42
Branch analysis from position: 33
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9QJVq
function name:  parse
number of ops:  44
compiled vars:  !0 = $string, !1 = $pattern, !2 = $format, !3 = $mask, !4 = $r, !5 = $matches, !6 = $buffer, !7 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        CAST                                          6  ~8      !0
          2        ASSIGN                                                   !0, ~8
   21     3        FETCH_OBJ_R                                      ~10     'pattern'
          4        ASSIGN                                                   !1, ~10
   22     5        FETCH_OBJ_R                                      ~12     'format'
          6        ASSIGN                                                   !2, ~12
   23     7        FETCH_OBJ_R                                      ~14     'mask'
          8        ASSIGN                                                   !3, ~14
   25     9        INIT_FCALL                                               'preg_match'
         10        SEND_VAR                                                 !1
         11        SEND_VAR                                                 !0
         12        SEND_REF                                                 !5
         13        DO_ICALL                                         $16     
         14        ASSIGN                                                   !4, $16
   26    15        BOOL_NOT                                         ~18     !4
         16      > JMPZ                                                     ~18, ->21
   27    17    >   NEW                                              $19     'UnexpectedValueException'
         18        SEND_VAL_EX                                              'Preg+Regex+Pattern+failed.'
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $19
   29    21    >   INIT_FCALL                                               'vsprintf'
         22        SEND_VAR                                                 !3
         23        SEND_VAR                                                 !5
         24        DO_ICALL                                         $21     
         25        ASSIGN                                                   !6, $21
   30    26        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         27        SEND_VAR                                                 !2
         28        SEND_VAR                                                 !6
         29        DO_FCALL                                      0  $23     
         30        ASSIGN                                                   !7, $23
   31    31        BOOL_NOT                                         ~25     !7
         32      > JMPZ                                                     ~25, ->42
   32    33    >   NEW                                              $26     'UnexpectedValueException'
         34        INIT_FCALL                                               'sprintf'
         35        SEND_VAL                                                 'Failed+To+Create+from+Format+%22%25s%22+for+%22%25s%22.'
         36        SEND_VAR                                                 !2
         37        SEND_VAR                                                 !6
         38        DO_ICALL                                         $27     
         39        SEND_VAR_NO_REF_EX                                       $27
         40        DO_FCALL                                      0          
         41      > THROW                                         0          $26
   34    42    > > RETURN                                                   !7
   35    43*     > RETURN                                                   null

End of function parse

End of class PregDateParser.

Class JsonTimestampWithOffsetParser: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.65 ms | 1404 KiB | 19 Q