diff --git a/backend-php/api.php b/backend-php/api.php index 621a144..7575dee 100644 --- a/backend-php/api.php +++ b/backend-php/api.php @@ -13,26 +13,26 @@ function findClosestDateSort($array, $targetDate) if (empty($array) || !preg_match('/^\d{1,2}-\d{1,2}-\d{2}$/', $targetDate)) { return null; } - + $targetDateTime = DateTime::createFromFormat('d-m-y', $targetDate); if ($targetDateTime === false) return null; $targetTimestamp = $targetDateTime->getTimestamp(); - + $result = null; $maxTimestamp = null; - + foreach ($array as $item) { $itemDateTime = DateTime::createFromFormat('d-m-y', $item['fromDate']); if ($itemDateTime === false) continue; - + $itemTimestamp = $itemDateTime->getTimestamp(); if ($itemTimestamp <= $targetTimestamp && ($maxTimestamp === null || $itemTimestamp > $maxTimestamp)) { $maxTimestamp = $itemTimestamp; $result = $item; } } - - return $result; + + return $result ?: ['content' => '[]']; } function getDayOfWeek(string $date) {