3v4l.org

run code in 300+ PHP versions simultaneously
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Turn off chat button if before/after hours</title> <meta name="description" content="untitled"> <meta name="author" content="Craig MacKinnon"> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> function offMode() { jQuery(".initChat").addClass("offline"); jQuery(".initChat").removeAttr("onclick"); } </script> <style> * { margin:0; font: normal 12px sans-serif; } .initChat { background: url(http://i.snag.gy/DIPT4.jpg) no-repeat top left; display: block; height: 111px; width: 32px; position: fixed; top: 70%; z-index: 99999; } .initChat:hover { background-position: -34px 0px; cursor: pointer; } .initChat.offline { background-position: -68px 0px; cursor: context-menu; } </style> </head> <body> <?php // set timezone to Eastern Time date_default_timezone_set('America/New_York'); $storeSchedule = [ 'Sun' => ['closed'], 'Mon' => ['09:00 AM' => '05:00 PM'], 'Tue' => ['09:00 AM' => '05:00 PM'], 'Wed' => ['09:00 AM' => '05:00 PM'], 'Thu' => ['09:00 AM' => '05:00 PM'], 'Fri' => ['09:00 AM' => '05:00 PM'], 'Sat' => ['closed'] ]; // current or user supplied UNIX timestamp $timestamp = time(); // default status $status = 'open'; // get current time object $currentTime = (new DateTime())->setTimestamp($timestamp); // loop through time ranges for current day foreach ($storeSchedule[date('D', $timestamp)] as $startTime => $endTime) { // create time objects from start/end times $startTime = DateTime::createFromFormat('h:i A', $startTime); $endTime = DateTime::createFromFormat('h:i A', $endTime); // check if current time is within a range if (($currentTime < $startTime) && ($currentTime > $endTime)) { $status = 'closed'; echo '<script>jQuery(function() { offMode(); });</script>'; break; } } echo "We are currently: $status"; echo "<br />"; echo "Server time: " . date('h:i A'); ?> <a class="initChat" onclick="window.open('https://admin.instantservice.com/links/7565/61447', 'custclient', 'width=612,height=380,scrollbars=0'); return false;"></a> </body> </html>

preferences:
32.1 ms | 402 KiB | 5 Q