Skip to content

Commit

Permalink
Renamed group functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
coryetzkorn committed Feb 20, 2016
1 parent c1b72c2 commit f63b117
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
10 changes: 5 additions & 5 deletions StoreHours.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private function hours_overview_format_hours(array $ranges)
/**
*
*/
private function hours_overview_simple()
private function hours_this_week_simple()
{
$lookup = array_combine(range(1, 7), $this->templates['overview_weekdays']);

Expand All @@ -294,7 +294,7 @@ private function hours_overview_simple()
*
* @return array
*/
private function hours_overview_grouped()
private function hours_this_week_grouped()
{
$lookup = array_combine(range(1, 7), $this->templates['overview_weekdays']);

Expand Down Expand Up @@ -367,10 +367,10 @@ private function hours_overview_grouped()
*
* @return array
*/
public function hours_overview($groupSameDays = false)
public function hours_this_week($groupSameDays = false)
{
return (true === $groupSameDays)
? $this->hours_overview_grouped()
: $this->hours_overview_simple();
? $this->hours_this_week_grouped()
: $this->hours_this_week_simple();
}
}
20 changes: 10 additions & 10 deletions StoreHoursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function testHoursOverviewSimple()
'Fri' => '-',
'Sat' => '-',
'Sun' => '-'
), $sh->hours_overview());
), $sh->hours_this_week());

$sh = new StoreHours(array('fri' => array('')));
$this->assertEquals(array(
Expand All @@ -237,7 +237,7 @@ public function testHoursOverviewSimple()
'Fri' => '-',
'Sat' => '-',
'Sun' => '-'
), $sh->hours_overview());
), $sh->hours_this_week());


$sh = new StoreHours(array(
Expand All @@ -255,7 +255,7 @@ public function testHoursOverviewSimple()
'Fri' => '8:00am-12:00pm, 1:00pm-1:30am',
'Sat' => '-',
'Sun' => '8:00am-1:30am'
), $sh->hours_overview());
), $sh->hours_this_week());
}

/**
Expand All @@ -264,18 +264,18 @@ public function testHoursOverviewSimple()
public function testHoursOverviewGrouped()
{
$sh = new StoreHours(array());
$this->assertEquals(array(), $sh->hours_overview(true));
$this->assertEquals(array(), $sh->hours_this_week(true));

$sh = new StoreHours(array('fri' => array('')));
$this->assertEquals(array(), $sh->hours_overview(true));
$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_overview(true));
), $sh->hours_this_week(true));


$sh = new StoreHours(array(
Expand All @@ -284,7 +284,7 @@ public function testHoursOverviewGrouped()
));
$this->assertEquals(array(
'Mon, Tue' => '8:00am-12:00pm, 1:00pm-1:30am'
), $sh->hours_overview(true));
), $sh->hours_this_week(true));


$sh = new StoreHours(array(
Expand All @@ -294,7 +294,7 @@ public function testHoursOverviewGrouped()
));
$this->assertEquals(array(
'Mon-Wed' => '8:00am-12:00pm, 1:00pm-1:30am'
), $sh->hours_overview(true));
), $sh->hours_this_week(true));


$sh = new StoreHours(array(
Expand All @@ -307,7 +307,7 @@ public function testHoursOverviewGrouped()
$this->assertEquals(array(
'Mon, Tue, Thu, Fri' => '8:00am-12:00pm, 1:00pm-1:30am',
'Sun' => '8:00am-1:30am'
), $sh->hours_overview(true));
), $sh->hours_this_week(true));


$sh = new StoreHours(array(
Expand All @@ -320,6 +320,6 @@ public function testHoursOverviewGrouped()
));
$this->assertEquals(array(
'Mon-Wed, Fri-Sun' => '8:00am-12:00pm, 1:00pm-1:30am'
), $sh->hours_overview(true));
), $sh->hours_this_week(true));
}
}
19 changes: 11 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
table {
font-size: small;
text-align: left;
margin: 150px auto 0 auto;
margin: 100px auto 0 auto;
border-collapse: collapse;
}
td {
Expand Down Expand Up @@ -64,23 +64,26 @@
// 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>",
'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", // options listed here: http://php.net/manual/en/function.date.php
'hours' => "{%open%}{%separator%}{%closed%}"
);

// Instantiate class and call render method to output content
// 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_overview() as $days => $hours) {
foreach ($store_hours->hours_this_week() as $days => $hours) {
echo '<tr>';
echo '<td>' . $days . '</td>';
echo '<td>' . $hours . '</td>';
Expand All @@ -90,7 +93,7 @@

// Same list, but group days with identical hours
echo '<table>';
foreach ($store_hours->hours_overview(true) as $days => $hours) {
foreach ($store_hours->hours_this_week(true) as $days => $hours) {
echo '<tr>';
echo '<td>' . $days . '</td>';
echo '<td>' . $hours . '</td>';
Expand Down

1 comment on commit f63b117

@mermshaus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, hours_this_week does not return the hours for “this week” but the hours for a “normal week.” The difference is that “this week” would need to consider $hours and $exceptions whereas “normal week” would only be based on $hours. It’s a bit of a semantic problem. :)

We should probably open an issue to discuss this naming/API stuff. I might do that later.

Edit: See #15

Please sign in to comment.