dx v2: fix no day match
This commit is contained in:
+6
-6
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user