Repository: spatie/opening-hours (php)

Issue:
previousOpen returns next open date
Hi! We are using your library (2.41.0) and looking for a way to find last opening time. As I understand `previousOpen` should do this, but seems that response is not correct. I tried to setup next opening hours:
* Monday: 18:00 - 05:00
* Tuesday: 18:00 - 05:00
And `previousOpen` with (Tuesday 06:00) returns (Tuesday 18:00), but I expect (Monday 18:00). So it returns `nextOpen`.

Created a test file such as:
```php
$openingHours = OpeningHours::create([
    'overflow' => true,
    'monday' => ['18:00-05:00'],
    'tuesday' => ['18:00-05:00'],
]);
$tuesday = new DateTime('2024-06-11 06:00:00');
echo 'Today          : ' . $tuesday->format('Y-m-d H:i') . "\n";
echo 'Previous open  : ' . $openingHours->previousOpen($tuesday)->format('Y-m-d H:i') . "\n";
echo 'Previous close : ' . $openingHours->previousClose($tuesday)->format('Y-m-d H:i') . "\n";
```
Response
``` cmd
Today          : 2024-06-11 06:00
Previous open  : 2024-06-11 18:00
Previous close : 2024-06-11 05:00
```
Could you please say if there's a problem with configuration or there any solution to solve this issue?

Pull request:
Check both start and end to consider a range before/after
Check both start and end to consider a range before/after

Fix #243

Patch:
diff --git a/src/Helpers/RangeFinder.php b/src/Helpers/RangeFinder.php
index 7dcf67c..77021da 100644
--- a/src/Helpers/RangeFinder.php
+++ b/src/Helpers/RangeFinder.php
@@ -44,7 +44,7 @@ trait RangeFinder
 
     protected function findPreviousRangeInFreeTime(Time $time, TimeRange $timeRange): ?TimeRange
     {
-        return $time->isAfter($timeRange->end()) ? $timeRange : null;
+        return $time->isAfter($timeRange->end()) && $time->isAfter($timeRange->start()) ? $timeRange : null;
     }
 
     protected function findPreviousOpenInFreeTime(Time $time, TimeRange $timeRange): ?Time


Test patch:
diff --git a/tests/OpeningHoursOverflowTest.php b/tests/OpeningHoursOverflowTest.php
index dc98ad1..1a9aebb 100644
--- a/tests/OpeningHoursOverflowTest.php
+++ b/tests/OpeningHoursOverflowTest.php
@@ -142,6 +142,20 @@ class OpeningHoursOverflowTest extends TestCase
         $this->assertSame('2019-04-22 02:00:00', $previousTimeOpen);
     }
 
+    #[Test]
+    public function previous_open_and_close_with_overflow_immutable()
+    {
+        $openingHours = OpeningHours::create([
+            'overflow' => true,
+            'monday' => ['18:00-05:00'],
+            'tuesday' => ['18:00-05:00'],
+        ]);
+        $tuesday = new DateTime('2024-06-11 06:00:00');
+
+        $this->assertSame('2024-06-10 18:00', $openingHours->previousOpen($tuesday)->format('Y-m-d H:i'));
+        $this->assertSame('2024-06-11 05:00', $openingHours->previousClose($tuesday)->format('Y-m-d H:i'));
+    }
+
     #[Test]
     public function overflow_on_simple_ranges()
     {