Skip to content

Commit

Permalink
Times starting at 00:00 caused infinite loop (#45)
Browse files Browse the repository at this point in the history
* Added a test to check if times set to 0:00 indeed lead to an infinite loop

* Fixed bug where 00:00 times caused an infinite loop

* Removed an opening hours to make sure the test runs with a 00:00 opening time

* File permissions for changelog & contributing as mentioned by SensioLabs Insight

* Added strict comparisation for start time

* Imported DateTime for OpeningHoursTest

* Used ->start()->same() method to compare times in OpeningHoursForDay
  • Loading branch information
joshuadegier authored and freekmurze committed Sep 13, 2017
1 parent f76a8b2 commit 082eb72
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Empty file modified CHANGELOG.md
100755 → 100644
Empty file.
Empty file modified CONTRIBUTING.md
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion src/OpeningHoursForDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function findNextOpenInFreeTime(Time $time, TimeRange $timeRange, Time
TimeRange::fromString($prevTimeRange->end().'-'.$timeRange->start()) :
TimeRange::fromString('00:00-'.$timeRange->start());

if ($timeOffRange->containsTime($time)) {
if ($timeOffRange->containsTime($time) || $timeOffRange->start()->isSame($time)) {
return $timeRange->start();
}

Expand Down
17 changes: 14 additions & 3 deletions tests/OpeningHoursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function it_can_determine_next_open_hours_from_non_working_date_time()

$nextTimeOpen = $openingHours->nextOpen(new DateTime('2016-09-26 12:00:00'));

$this->assertInstanceOf('\DateTime', $nextTimeOpen);
$this->assertInstanceOf('DateTime', $nextTimeOpen);
$this->assertEquals('2016-09-26 13:00:00', $nextTimeOpen->format('Y-m-d H:i:s'));
}

Expand All @@ -176,7 +176,7 @@ public function it_can_determine_next_open_hours_from_working_date_time()

$nextTimeOpen = $openingHours->nextOpen(new DateTime('2016-09-26 16:00:00'));

$this->assertInstanceOf('\DateTime', $nextTimeOpen);
$this->assertInstanceOf('DateTime', $nextTimeOpen);
$this->assertEquals('2016-09-27 10:00:00', $nextTimeOpen->format('Y-m-d H:i:s'));
}

Expand All @@ -193,7 +193,7 @@ public function it_can_determine_next_open_hours_from_early_morning()

$nextTimeOpen = $openingHours->nextOpen(new DateTime('2016-09-26 04:00:00'));

$this->assertInstanceOf('\DateTime', $nextTimeOpen);
$this->assertInstanceOf('DateTime', $nextTimeOpen);
$this->assertEquals('2016-09-27 10:00:00', $nextTimeOpen->format('Y-m-d H:i:s'));
}

Expand Down Expand Up @@ -298,4 +298,15 @@ public function it_can_retrieve_a_list_of_exceptional_closing_dates()
$this->assertEquals('2017-06-01', $exceptionalClosingDates[0]->format('Y-m-d'));
$this->assertEquals('2017-06-02', $exceptionalClosingDates[1]->format('Y-m-d'));
}

/** @test */
public function it_works_when_starting_at_midnight()
{
$openingHours = OpeningHours::create([
'monday' => ['00:00-16:00'],
]);

$nextTimeOpen = $openingHours->nextOpen(new DateTime());
$this->assertInstanceOf('DateTime', $nextTimeOpen);
}
}

0 comments on commit 082eb72

Please sign in to comment.