Repository: spatie/opening-hours (php)
Issue: No close date/time found in the previous 8 days, use $openingHours->setDayLimit() to increase the limit.
It returns the error:
No close date/time found in the previous 8 days, use $openingHours->setDayLimit() to increase the limit.

Meanwhile, the schedule or data seems to be valid.

Schedule Data:
```php
$schedule = [
     "monday" => ["10:00-23:59"],
     "tuesday" => ["10:00-23:59"],
     "wednesday" => ["10:00-23:59"]
     "thursday" => ["10:00-23:59"]
     "friday" => ["10:00-23:59"]
     "saturday" => ["10:00-23:59"]
     "sunday" => ["10:00-23:59"]
];
```

We're using:
```php
$openingHours = OpeningHours::createAndMergeOverlappingRanges(
      data: $schedule,
      timezone: config('openinghours.timezone'), // Australia/Brisbane
)
```

```php
$now = new DateTime('2025-05-23 09:00:00', new DateTimeZone('Australia/Brisbane')); // Friday
$openingHours->previousClose($now);
```

Expected:
```php
Thu 23:59
```


Pull request description: Fix previousClose with custom timezone
Fix #273

Patch:
diff --git a/src/OpeningHours.php b/src/OpeningHours.php
index 45aab1e..6c9ac0a 100644
--- a/src/OpeningHours.php
+++ b/src/OpeningHours.php
@@ -624,7 +624,7 @@ class OpeningHours
             }
 
             $midnight = $dateTime->setTime(0, 0, 0);
-            $dateTime = $this->copyAndModify($midnight, '-1 minute');
+            $dateTime = $this->copyAndModify($midnight, '-1 second');
 
             $openingHoursForDay = $this->forDate($dateTime);
 
@@ -683,7 +683,7 @@ class OpeningHours
             }
 
             $midnight = $dateTime->setTime(0, 0, 0);
-            $dateTime = $this->copyAndModify($midnight, '-1 minute');
+            $dateTime = $this->copyAndModify($midnight, '-1 second');
             $openingHoursForDay = $this->forDate($dateTime);
 
             if ($this->isClosedAt($midnight) && $openingHoursForDay->isOpenAtTheEndOfTheDay()) {


Test patch:
diff --git a/tests/OpeningHoursStructuredDataTest.php b/tests/OpeningHoursStructuredDataTest.php
index 16d6cb4..df41496 100644
--- a/tests/OpeningHoursStructuredDataTest.php
+++ b/tests/OpeningHoursStructuredDataTest.php
@@ -2,6 +2,7 @@
 
 namespace Spatie\OpeningHours\Test;
 
+use DateTime;
 use DateTimeZone;
 use PHPUnit\Framework\Attributes\Test;
 use PHPUnit\Framework\TestCase;
@@ -83,4 +84,30 @@ class OpeningHoursStructuredDataTest extends TestCase
 
         $this->assertSame('17:00:00+12:45', $openingHours->asStructuredData('H:i:sP', new DateTimeZone('+12:45'))[0]['closes']);
     }
+
+    #[Test]
+    public function it_can_find_previous_close_time_with_custom_timezone()
+    {
+        $schedule = [
+            'monday' => ['10:00-23:59'],
+            'tuesday' => ['10:00-23:59'],
+            'wednesday' => ['10:00-23:59'],
+            'thursday' => ['10:00-23:59'],
+            'friday' => ['10:00-23:59'],
+            'saturday' => ['10:00-23:59'],
+            'sunday' => ['10:00-23:59'],
+        ];
+
+        $openingHours = OpeningHours::createAndMergeOverlappingRanges(
+            data: $schedule,
+            timezone: 'Australia/Brisbane',
+        );
+
+        $now = new DateTime('2025-05-23 09:00:00', new DateTimeZone('Australia/Brisbane'));
+
+        $this->assertSame(
+            '2025-05-22 23:59:00 Australia/Brisbane',
+            $openingHours->previousClose($now)->format('Y-m-d H:i:s e'),
+        );
+    }
 }