3v4l.org

run code in 500+ PHP versions simultaneously
<?php date_default_timezone_set('Europe/Stockholm'); function displayAllowPostsMessage($dateTime, $isDebug = false) { $weekdayStartTime = new DateTime('09:00'); $weekdayEndTime = new DateTime('19:00'); $saturdayStartTime = new DateTime('10:00'); $saturdayEndTime = new DateTime('15:00'); $templateOpen = "It's %s and we are open!"; $templateClosed = "It's %s and the posting are only allowed between %s - %s. Sorry for the Inconvenience."; $dayOfTheWeek = intval($dateTime->format('N')); $message = "It's closed on sunday."; if ($isDebug) { $weekdayStartTime->setDate((int)$dateTime->format('Y'), (int)$dateTime->format('m'), (int)$dateTime->format('d')); $weekdayEndTime->setDate((int)$dateTime->format('Y'), (int)$dateTime->format('m'), (int)$dateTime->format('d')); $saturdayStartTime->setDate((int)$dateTime->format('Y'), (int)$dateTime->format('m'), (int)$dateTime->format('d')); $saturdayEndTime->setDate((int)$dateTime->format('Y'), (int)$dateTime->format('m'), (int)$dateTime->format('d')); } // On a weekday if ($dayOfTheWeek < 6) { $isOpen = $dateTime > $weekdayStartTime && $dateTime < $weekdayEndTime; $message = sprintf( $templateOpen, $dateTime->format('l H:i') ); if (!$isOpen) { $message = sprintf( $templateClosed, $dateTime->format('l H:i'), $weekdayStartTime->format("H:i"), $weekdayEndTime->format("H:i") ); } } // On a saturday if ($dayOfTheWeek === 6) { $isOpen = $dateTime > $saturdayStartTime && $dateTime < $saturdayEndTime; $message = sprintf( $templateOpen, $dateTime->format('l H:i') ); if (!$isOpen) { $message = sprintf( $templateClosed, $dateTime->format('l H:i'), $saturdayStartTime->format("H:i"), $saturdayEndTime->format("H:i") ); } } echo "$message\n"; } $testDates = array( DateTime::createFromFormat('d/m/Y H:i', '18/12/2015 08:59'), // friday DateTime::createFromFormat('d/m/Y H:i', '18/12/2015 09:00'), DateTime::createFromFormat('d/m/Y H:i', '18/12/2015 09:01'), DateTime::createFromFormat('d/m/Y H:i', '18/12/2015 18:59'), DateTime::createFromFormat('d/m/Y H:i', '18/12/2015 19:00'), DateTime::createFromFormat('d/m/Y H:i', '18/12/2015 19:01'), DateTime::createFromFormat('d/m/Y H:i', '19/12/2015 09:59'), // saturday DateTime::createFromFormat('d/m/Y H:i', '19/12/2015 10:00'), DateTime::createFromFormat('d/m/Y H:i', '19/12/2015 10:01'), DateTime::createFromFormat('d/m/Y H:i', '19/12/2015 14:59'), DateTime::createFromFormat('d/m/Y H:i', '19/12/2015 15:00'), DateTime::createFromFormat('d/m/Y H:i', '19/12/2015 15:01'), DateTime::createFromFormat('d/m/Y H:i', '20/12/2015 11:30') // sunday ); foreach ($testDates as $testDate) { displayAllowPostsMessage($testDate, true); }
Output for rfc.property-hooks, git.master_jit, git.master
It's Friday 08:59 and the posting are only allowed between 09:00 - 19:00. Sorry for the Inconvenience. It's Friday 09:00 and the posting are only allowed between 09:00 - 19:00. Sorry for the Inconvenience. It's Friday 09:01 and we are open! It's Friday 18:59 and we are open! It's Friday 19:00 and the posting are only allowed between 09:00 - 19:00. Sorry for the Inconvenience. It's Friday 19:01 and the posting are only allowed between 09:00 - 19:00. Sorry for the Inconvenience. It's Saturday 09:59 and the posting are only allowed between 10:00 - 15:00. Sorry for the Inconvenience. It's Saturday 10:00 and the posting are only allowed between 10:00 - 15:00. Sorry for the Inconvenience. It's Saturday 10:01 and we are open! It's Saturday 14:59 and we are open! It's Saturday 15:00 and the posting are only allowed between 10:00 - 15:00. Sorry for the Inconvenience. It's Saturday 15:01 and the posting are only allowed between 10:00 - 15:00. Sorry for the Inconvenience. It's closed on sunday.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.91 ms | 2514 KiB | 4 Q