3v4l.org

run code in 300+ PHP versions simultaneously
<?php const SECONDS_PER_MINUTE = 60; const SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE; const SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR; const DAYS_PER_YEAR = 365; const DAYS_PER_LEAP_YEAR = DAYS_PER_YEAR + 1; const EPOCH_MONTH = 1; const EPOCH_YEAR = 1970; function getDateTime(int $timestamp) : array { $days = intdiv($timestamp, SECONDS_PER_DAY); $year = EPOCH_YEAR; while ($days >= getDaysForYear($year)) { $days -= getDaysForYear($year); $year++; } $daysPerMonth = getDaysPerMonth($year); $month = EPOCH_MONTH; while ($days >= $daysPerMonth[$month]) { $days -= $daysPerMonth[$month]; $month++; } $day = $days + 1; $secondsRemaining = $timestamp % SECONDS_PER_DAY; $hour = intdiv($secondsRemaining, SECONDS_PER_HOUR); $minute = intdiv($secondsRemaining, SECONDS_PER_MINUTE) % SECONDS_PER_MINUTE; $second = $secondsRemaining % SECONDS_PER_MINUTE; return [ 'year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $second ]; } function isLeapYear(int $year) : bool { return $year % 400 === 0 || ($year % 4 === 0 && $year % 100 !== 0); } function getDaysForYear(int $year) : int { return isLeapYear($year) ? DAYS_PER_LEAP_YEAR : DAYS_PER_YEAR; } function getDaysPerMonth(int $year) : array { return [0, 31, isLeapYear($year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; } $time = 1471488076; //08/18/2016 @ 2:41am (UTC) print_r(getDateTime($time));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oDLh2
function name:  (null)
number of ops:  15
compiled vars:  !0 = $time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'SECONDS_PER_MINUTE', 60
    4     1        DECLARE_CONST                                            'SECONDS_PER_HOUR', <const ast>
    5     2        DECLARE_CONST                                            'SECONDS_PER_DAY', <const ast>
    7     3        DECLARE_CONST                                            'DAYS_PER_YEAR', 365
    8     4        DECLARE_CONST                                            'DAYS_PER_LEAP_YEAR', <const ast>
   10     5        DECLARE_CONST                                            'EPOCH_MONTH', 1
   11     6        DECLARE_CONST                                            'EPOCH_YEAR', 1970
   62     7        ASSIGN                                                   !0, 1471488076
   63     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL                                               'getdatetime'
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function getdatetime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 10
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 27
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 27
Branch analysis from position: 33
Branch analysis from position: 27
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 10
Branch analysis from position: 20
Branch analysis from position: 10
filename:       /in/oDLh2
function name:  getDateTime
number of ops:  65
compiled vars:  !0 = $timestamp, !1 = $days, !2 = $year, !3 = $daysPerMonth, !4 = $month, !5 = $day, !6 = $secondsRemaining, !7 = $hour, !8 = $minute, !9 = $second
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'intdiv'
          2        SEND_VAR                                                 !0
          3        FETCH_CONSTANT                                   ~10     'SECONDS_PER_DAY'
          4        SEND_VAL                                                 ~10
          5        DO_ICALL                                         $11     
          6        ASSIGN                                                   !1, $11
   17     7        FETCH_CONSTANT                                   ~13     'EPOCH_YEAR'
          8        ASSIGN                                                   !2, ~13
   18     9      > JMP                                                      ->15
   19    10    >   INIT_FCALL_BY_NAME                                       'getDaysForYear'
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $15     
         13        ASSIGN_OP                                     2          !1, $15
   20    14        PRE_INC                                                  !2
   18    15    >   INIT_FCALL_BY_NAME                                       'getDaysForYear'
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0  $18     
         18        IS_SMALLER_OR_EQUAL                                      $18, !1
         19      > JMPNZ                                                    ~19, ->10
   23    20    >   INIT_FCALL_BY_NAME                                       'getDaysPerMonth'
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0  $20     
         23        ASSIGN                                                   !3, $20
   24    24        FETCH_CONSTANT                                   ~22     'EPOCH_MONTH'
         25        ASSIGN                                                   !4, ~22
   25    26      > JMP                                                      ->30
   26    27    >   FETCH_DIM_R                                      ~24     !3, !4
         28        ASSIGN_OP                                     2          !1, ~24
   27    29        PRE_INC                                                  !4
   25    30    >   FETCH_DIM_R                                      ~27     !3, !4
         31        IS_SMALLER_OR_EQUAL                                      ~27, !1
         32      > JMPNZ                                                    ~28, ->27
   30    33    >   ADD                                              ~29     !1, 1
         34        ASSIGN                                                   !5, ~29
   32    35        FETCH_CONSTANT                                   ~31     'SECONDS_PER_DAY'
         36        MOD                                              ~32     !0, ~31
         37        ASSIGN                                                   !6, ~32
   33    38        INIT_FCALL                                               'intdiv'
         39        SEND_VAR                                                 !6
         40        FETCH_CONSTANT                                   ~34     'SECONDS_PER_HOUR'
         41        SEND_VAL                                                 ~34
         42        DO_ICALL                                         $35     
         43        ASSIGN                                                   !7, $35
   34    44        INIT_FCALL                                               'intdiv'
         45        SEND_VAR                                                 !6
         46        FETCH_CONSTANT                                   ~37     'SECONDS_PER_MINUTE'
         47        SEND_VAL                                                 ~37
         48        DO_ICALL                                         $38     
         49        FETCH_CONSTANT                                   ~39     'SECONDS_PER_MINUTE'
         50        MOD                                              ~40     $38, ~39
         51        ASSIGN                                                   !8, ~40
   35    52        FETCH_CONSTANT                                   ~42     'SECONDS_PER_MINUTE'
         53        MOD                                              ~43     !6, ~42
         54        ASSIGN                                                   !9, ~43
   38    55        INIT_ARRAY                                       ~45     !2, 'year'
   39    56        ADD_ARRAY_ELEMENT                                ~45     !4, 'month'
   40    57        ADD_ARRAY_ELEMENT                                ~45     !5, 'day'
   41    58        ADD_ARRAY_ELEMENT                                ~45     !7, 'hour'
   42    59        ADD_ARRAY_ELEMENT                                ~45     !8, 'minute'
   43    60        ADD_ARRAY_ELEMENT                                ~45     !9, 'second'
         61        VERIFY_RETURN_TYPE                                       ~45
         62      > RETURN                                                   ~45
   45    63*       VERIFY_RETURN_TYPE                                       
         64*     > RETURN                                                   null

End of function getdatetime

Function isleapyear:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
Branch analysis from position: 11
filename:       /in/oDLh2
function name:  isLeapYear
number of ops:  15
compiled vars:  !0 = $year
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   49     1        MOD                                              ~1      !0, 400
          2        IS_IDENTICAL                                     ~2      ~1, 0
          3      > JMPNZ_EX                                         ~2      ~2, ->11
          4    >   MOD                                              ~3      !0, 4
          5        IS_IDENTICAL                                     ~4      ~3, 0
          6      > JMPZ_EX                                          ~4      ~4, ->10
          7    >   MOD                                              ~5      !0, 100
          8        IS_NOT_IDENTICAL                                 ~6      ~5, 0
          9        BOOL                                             ~4      ~6
         10    >   BOOL                                             ~2      ~4
         11    >   VERIFY_RETURN_TYPE                                       ~2
         12      > RETURN                                                   ~2
   50    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function isleapyear

Function getdaysforyear:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oDLh2
function name:  getDaysForYear
number of ops:  14
compiled vars:  !0 = $year
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   53     1        INIT_FCALL                                               'isleapyear'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $1      
          4      > JMPZ                                                     $1, ->8
          5    >   FETCH_CONSTANT                                   ~2      'DAYS_PER_LEAP_YEAR'
          6        QM_ASSIGN                                        ~3      ~2
          7      > JMP                                                      ->10
          8    >   FETCH_CONSTANT                                   ~4      'DAYS_PER_YEAR'
          9        QM_ASSIGN                                        ~3      ~4
         10    >   VERIFY_RETURN_TYPE                                       ~3
         11      > RETURN                                                   ~3
   54    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function getdaysforyear

Function getdayspermonth:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oDLh2
function name:  getDaysPerMonth
number of ops:  25
compiled vars:  !0 = $year
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   58     1        INIT_ARRAY                                       ~1      0
          2        ADD_ARRAY_ELEMENT                                ~1      31
          3        INIT_FCALL                                               'isleapyear'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6      > JMPZ                                                     $2, ->9
          7    >   QM_ASSIGN                                        ~3      29
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~3      28
         10    >   ADD_ARRAY_ELEMENT                                ~1      ~3
         11        ADD_ARRAY_ELEMENT                                ~1      31
         12        ADD_ARRAY_ELEMENT                                ~1      30
         13        ADD_ARRAY_ELEMENT                                ~1      31
         14        ADD_ARRAY_ELEMENT                                ~1      30
         15        ADD_ARRAY_ELEMENT                                ~1      31
         16        ADD_ARRAY_ELEMENT                                ~1      31
         17        ADD_ARRAY_ELEMENT                                ~1      30
         18        ADD_ARRAY_ELEMENT                                ~1      31
         19        ADD_ARRAY_ELEMENT                                ~1      30
         20        ADD_ARRAY_ELEMENT                                ~1      31
         21        VERIFY_RETURN_TYPE                                       ~1
         22      > RETURN                                                   ~1
   59    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null

End of function getdayspermonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
275.11 ms | 1027 KiB | 18 Q