Skip to content

Commit

Permalink
Fix #88 Opening hours across Midnight
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Feb 13, 2019
1 parent 0c04c99 commit 85aba22
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ php:
- 7.1
- 7.2
- 7.3
- 8.0
- nightly

matrix:
include:
- php: 8.0
env: COMPOSER_PLATEFORM_REQS="--ignore-platform-reqs"
- php: nightly
env: COMPOSER_PLATEFORM_REQS="--ignore-platform-reqs"
- php: 7.3
env: MULTITEST='on'
allow_failures:
Expand All @@ -18,13 +20,14 @@ matrix:
fast_finish: true

env:
- COMPOSER_PLATEFORM_REQS=""
matrix:
- COMPOSER_FLAGS="--prefer-lowest"
- COMPOSER_FLAGS=""

before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
- travis_retry composer update ${COMPOSER_FLAGS} ${COMPOSER_PLATEFORM_REQS} --no-interaction --prefer-source

script:
- if [ "$MULTITEST" != "on" ]; then phpunit --coverage-text --coverage-clover=coverage.clover; fi;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"php": "^7.0"
},
"require-dev": {
"kylekatarnls/multi-tester": "^1.0",
"kylekatarnls/multi-tester": "^1.1",
"phpunit/phpunit": "^6.4"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions src/OpeningHours.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function nextClose(DateTimeInterface $dateTime): DateTimeInterface
->modify('+1 day')
->setTime(0, 0, 0);

if ($this->isClosedAt($dateTime)) {
if ($this->isClosedAt($dateTime) && $openingHoursForDay->isOpenAt(Time::fromString('23:59'))) {
return $dateTime;
}

Expand Down Expand Up @@ -309,7 +309,7 @@ public function regularClosingDaysISO(): array

public function exceptionalClosingDates(): array
{
$dates = array_keys($this->filterExceptions(function (OpeningHoursForDay $openingHoursForDay, $date) {
$dates = array_keys($this->filterExceptions(function (OpeningHoursForDay $openingHoursForDay) {
return $openingHoursForDay->isEmpty();
}));

Expand Down
12 changes: 6 additions & 6 deletions tests/OpeningHoursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,10 @@ public function it_can_determine_next_close_hours_from_early_morning()
],
]);

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

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

/** @test */
Expand All @@ -554,10 +554,10 @@ public function it_can_determine_next_close_hours_from_early_morning_immutable()
],
]);

$nextTimeOpen = $openingHours->nextClose(new DateTimeImmutable('2016-09-26 04:00:00'));
$nextClosedTime = $openingHours->nextClose(new DateTimeImmutable('2016-09-26 04:00:00'));

$this->assertInstanceOf(DateTimeImmutable::class, $nextTimeOpen);
$this->assertEquals('2016-09-27 11:00:00', $nextTimeOpen->format('Y-m-d H:i:s'));
$this->assertInstanceOf(DateTimeImmutable::class, $nextClosedTime);
$this->assertEquals('2016-09-27 11:00:00', $nextClosedTime->format('Y-m-d H:i:s'));
}

/** @test */
Expand Down

0 comments on commit 85aba22

Please sign in to comment.