// Define daily open hours // Must be in 24-hour format, separated by dash // If closed for the day, leave blank (ex. sunday) // If open multiple times in one day, enter time ranges separated by a comma $hours = array('mon' => array('11:00-20:30'), 'tue' => array('11:00-13:00', '18:00-20:30'), 'wed' => array('11:00-20:30'), 'thu' => array('11:00-1:30'), 'fri' => array('11:00-20:30'), 'sat' => array('11:00-20:00'), 'sun' => array()); // OPTIONAL // Add exceptions (great for holidays etc.) // MUST be in a format month/day[/year] or [year-]month-day // Do not include the year if the exception repeats annually $exceptions = array('2/24' => array('11:00-18:00'), '10/18' => array('11:00-16:00', '18:00-20:30')); // OPTIONAL // Place HTML for output below. This is what will show in the browser. // Use {%hours%} shortcode to add dynamic times to your open or closed message. $template = array('open' => "Yes, we're open! Today's hours are {%hours%}.", 'closed' => "Sorry, we're closed. Today's hours are {%hours%}.", 'closed_all_day' => "Sorry, we're closed today.", 'separator' => " - ", 'join' => " and ", 'format' => "g:ia", 'hours' => "{%open%}{%separator%}{%closed%}"); // Instantiate class $store_hours = new StoreHours($hours, $exceptions, $template); // Call render method to output open / closed message echo '<h3>'; $store_hours->render(); echo '</h3>'; // Display full list of open hours (for a week without exceptions) echo '<table>'; foreach ($store_hours->hours_this_week() as $days => $hours) { echo '<tr>'; echo '<td>' . $days . '</td>'; echo '<td>' . $hours . '</td>'; echo '</tr>'; } echo '</table>'; // Same list, but group days with identical hours echo '<table>';
</div><!-- column --> <div class="column three last"> <strong>Hours</strong> <em>Tuesday - Thursday</em><br/> 1:00 - 9:00 pm<br/><br/> <em>Friday - Saturday</em><br/> 4:00 - 11:00 pm<br/><br/> <em>Sunday</em><br/> Closed<br/><br/> <?php date_default_timezone_set('America/New_York'); $storeHours = new StoreHours($hours, $exceptions, $template); $storeHours->render(); ?> </div><!-- column --> </div><!-- #footer --> <small>©<?php echo date('Y'); ?> <?php echo $companyName; ?> </small> </div><!-- .content -->
/** * */ public function testHoursOverviewGrouped() { $sh = new StoreHours(array()); $this->assertEquals(array(), $sh->hours_this_week(true)); $sh = new StoreHours(array('fri' => array(''))); $this->assertEquals(array(), $sh->hours_this_week(true)); $sh = new StoreHours(array('sun' => array('08:00-12:00'))); $this->assertEquals(array('Sun' => '8:00am-12:00pm'), $sh->hours_this_week(true)); $sh = new StoreHours(array('mon' => array('08:00-12:00', '13:00-1:30'), 'tue' => array('08:00-12:00', '13:00-1:30'))); $this->assertEquals(array('Mon, Tue' => '8:00am-12:00pm, 1:00pm-1:30am'), $sh->hours_this_week(true)); $sh = new StoreHours(array('mon' => array('08:00-12:00', '13:00-1:30'), 'tue' => array('08:00-12:00', '13:00-1:30'), 'wed' => array('08:00-12:00', '13:00-1:30'))); $this->assertEquals(array('Mon-Wed' => '8:00am-12:00pm, 1:00pm-1:30am'), $sh->hours_this_week(true)); $sh = new StoreHours(array('mon' => array('08:00-12:00', '13:00-1:30'), 'tue' => array('08:00-12:00', '13:00-1:30'), 'thu' => array('08:00-12:00', '13:00-1:30'), 'fri' => array('08:00-12:00', '13:00-1:30'), 'sun' => array('08:00-1:30'))); $this->assertEquals(array('Mon, Tue, Thu, Fri' => '8:00am-12:00pm, 1:00pm-1:30am', 'Sun' => '8:00am-1:30am'), $sh->hours_this_week(true)); $sh = new StoreHours(array('mon' => array('08:00-12:00', '13:00-1:30'), 'tue' => array('08:00-12:00', '13:00-1:30'), 'wed' => array('08:00-12:00', '13:00-1:30'), 'fri' => array('08:00-12:00', '13:00-1:30'), 'sat' => array('08:00-12:00', '13:00-1:30'), 'sun' => array('08:00-12:00', '13:00-1:30'))); $this->assertEquals(array('Mon-Wed, Fri-Sun' => '8:00am-12:00pm, 1:00pm-1:30am'), $sh->hours_this_week(true)); }
<h2>Store Hours</h2> <?php // REQUIRED // Set your default time zone (listed here: http://php.net/manual/en/timezones.php) date_default_timezone_set('America/New_York'); // Include the store hours class require 'StoreHours.class.php'; // REQUIRED // Define daily open hours // Must be in 24-hour format, separated by dash // If closed for the day, leave blank (ex. sunday) // If open multiple times in one day, enter time ranges separated by a comma $hours = array('mon' => array('11:00-20:30'), 'tue' => array('11:00-13:00', '18:00-20:30'), 'wed' => array('11:00-20:30'), 'thu' => array('11:00-1:30'), 'fri' => array('11:00-20:30'), 'sat' => array('11:00-20:00'), 'sun' => array('')); // OPTIONAL // Add exceptions (great for holidays etc.) // MUST be in format month/day // Do not include the year if the exception repeats annually $exceptions = array('2/24' => array('11:00-18:00'), '10/18' => array('11:00-16:00', '18:00-20:30')); // OPTIONAL // Place HTML for output below. This is what will show in the browser. // Use {%hours%} shortcode to add dynamic times to your open or closed message. $template = array('open' => "<h3>Yes, we're open! Today's hours are {%hours%}.</h3>", 'closed' => "<h3>Sorry, we're closed. Today's hours are {%hours%}.</h3>", 'closed_all_day' => "<h3>Sorry, we're closed today.</h3>", 'separator' => " - ", 'join' => " and ", 'format' => "g:ia", 'hours' => "{%open%}{%separator%}{%closed%}"); // Instantiate class and call render method to output content $store_hours = new StoreHours($hours, $exceptions, $template); $store_hours->render(); ?> </body> </html>