/**
  *
  */
 public function testWithCustomTemplates()
 {
     $hours = array('mon' => array('09:00-17:00', '17:30-18:00', '19:00-02:30'), 'thu' => array('17:45-18:00'));
     $exceptions = array('2016-02-15' => array());
     $templates = array('open' => 'Open. Hours {%hours%}.', 'separator' => '-', 'format' => 'G.i');
     $sh = new StoreHours($hours, $exceptions, $templates);
     ob_start();
     $sh->render(strtotime('2016-02-08 14:30:00'));
     // mon
     $this->assertEquals('Open. Hours 9.00-17.00 and 17.30-18.00 and 19.00-2.30.', ob_get_clean());
     ob_start();
     $sh->render(strtotime('2016-02-11 14:30:00'));
     // thu
     $this->assertEquals('<h3>Sorry, we\'re closed. Today\'s hours are 17.45-18.00.</h3>', ob_get_clean());
     ob_start();
     $sh->render(strtotime('2016-02-15 14:30:00'));
     // mon
     $this->assertEquals('<h3>Sorry, we\'re closed.</h3>', ob_get_clean());
 }
Esempio n. 2
0
// 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>';
foreach ($store_hours->hours_this_week(true) as $days => $hours) {
    echo '<tr>';
    echo '<td>' . $days . '</td>';
				
				<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>&copy;<?php 
echo date('Y');
?>
 <?php 
echo $companyName;
?>
</small>
			
		</div><!-- .content -->