예제 #1
0
// 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>';
    echo '<td>' . $hours . '</td>';
    echo '</tr>';
}
echo '</table>';
예제 #2
0
 /**
  *
  */
 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));
 }