dx v2: stupid ai fix

This commit is contained in:
2026-01-10 18:04:41 +03:00
parent ff1174671a
commit 8fe904eebe
+23 -10
View File
@@ -10,16 +10,29 @@ function db()
function findClosestDateSort($array, $targetDate)
{
if (!preg_match('/\d{1,2}-\d{1,2}-(\d{2}|\d{4})$/', $targetDate)) return;
$targetTimestamp = DateTime::createFromFormat('d-m-y', $targetDate)->getTimestamp();
usort($array, function ($a, $b) use ($targetTimestamp) {
$aTimestamp = DateTime::createFromFormat('d-m-y', $a['fromDate'])->getTimestamp();
$bTimestamp = DateTime::createFromFormat('d-m-y', $b['fromDate'])->getTimestamp();
$aDiff = abs($aTimestamp - $targetTimestamp);
$bDiff = abs($bTimestamp - $targetTimestamp);
return $aDiff - $bDiff;
});
return $array[0];
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;
}
function getDayOfWeek(string $date)
{