3v4l.org

run code in 300+ PHP versions simultaneously
<?php //function checkDeliveryPeriod(bool $isGas = false) //{ // $startDate = new DateTime('2020-08-01 00:00:00'); // $endDate = new DateTime('2024-02-16'); // // initial // $originReadAt = new DateTime('2024-02-17 00:00:00'); // $readAt = clone $originReadAt; // if ($isGas && $endDate !== null && $readAt > $endDate) { // //Gas day case: gas day ends at 6:00 next day // $readAt->subHours(6); // } // $readAt->setTime(0, 0, 0); // // // assure contract start date // if ($startDate == null) { // return false; // } // //special case when the start and end dates of the contract are the same // $startEndOnSameDay = ( // ($originReadAt->format('H:i') == '00:00') // && ($endDate === $startDate) // ); // // final check // return ( // $readAt >= $startDate // && ( // $endDate === null // || ($endDate !== null && $readAt <= $endDate) // ) // ) || $startEndOnSameDay; //} // //var_dump(checkDeliveryPeriod()); function determineNewRunAt(\DateTimeInterface $createdAt): DateTime { $nextRunAt = new DateTime(); $oneMonth = (clone $createdAt)->modify('1month'); $diff = $nextRunAt->diff($createdAt); var_dump($diff->days, $diff->h); // time out after one month after creation if ($nextRunAt >= $oneMonth) { throw new \Exception('Waiting time expired'); } // run the action once a day, if it was not finished within 1 day after creation if ($diff->days >= 1) { return $nextRunAt->modify('1day'); } return $diff->h === 0 ? $nextRunAt->modify('5minute') // run the action every 5 minutes within the first hour after creation : $nextRunAt->modify('1hour'); // run the action every hour for one day after creation } $nextRunAt = determineNewRunAt(new DateTime('2024-04-10 07:15')); var_dump($nextRunAt->format('Y-m-d h:i:s')); $nextRunAt = determineNewRunAt(new DateTime('2024-04-10 06:15')); var_dump($nextRunAt->format('Y-m-d h:i:s')); $nextRunAt = determineNewRunAt(new DateTime('2024-04-09 06:15')); var_dump($nextRunAt->format('Y-m-d h:i:s')); try { $nextRunAt = determineNewRunAt(new DateTime('2024-03-09 06:15')); } catch (\Throwable $e) { var_dump($e->getMessage()); }
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.17, 8.2.19 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
int(0) int(0) string(19) "2024-04-10 07:54:32" int(0) int(1) string(19) "2024-04-10 08:49:32" int(1) int(1) string(19) "2024-04-11 07:49:32" int(32) int(1) string(20) "Waiting time expired"
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.2.18
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.2.18/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.2.18/modules/sodium.so.so (/usr/lib/php/8.2.18/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 int(0) int(0) string(19) "2024-04-10 07:54:32" int(0) int(1) string(19) "2024-04-10 08:49:32" int(1) int(1) string(19) "2024-04-11 07:49:32" int(32) int(1) string(20) "Waiting time expired"

preferences:
91.95 ms | 410 KiB | 5 Q