diff --git a/classes/Location.php b/classes/Location.php index c0d9c83..dc990b3 100644 --- a/classes/Location.php +++ b/classes/Location.php @@ -310,6 +310,26 @@ public function scheduleTimeslot($orderType = null) $this->orderTimeInterval(), null, $leadMinutes ); + $firstDate = $result->keys()->first(); + + $firstDateObject = $result->pull($firstDate); + + $firstTime = array_slice($firstDateObject, 0, 1, true); + + $firstTime = $firstTime[array_key_first($firstTime)]; + + while (Carbon::now()->diffInMinutes($firstTime) < $this->orderLeadTime()) + { + $firstDateObject = array_slice($firstDateObject, 1, count($firstDateObject) - 1, true); + + $firstTime = array_slice($firstDateObject, 0, 1, true); + $firstTime = $firstTime[array_key_first($firstTime)]; + } + + $result->put($firstDate, $firstDateObject); + + $result = $result->sortKeys(); + return $this->scheduleCache[$orderType] = $result; }