Fix Jalali year-0 crash on /tasks from invalid target_date.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-22 17:56:39 +03:30
co-authored by Cursor
parent dc276dfbb5
commit 6caee30d9b
7 changed files with 37 additions and 15 deletions
+19
View File
@@ -39,4 +39,23 @@ class JalaliHelper
return $jalali ? $jalali->format($format) : $fallback;
}
/** تاریخ میلادی امن به صورت Y-m-d */
public static function toGregorianDate($value, string $fallback = ''): string
{
if ($value === null || $value === '' || str_starts_with((string) $value, '0000-00-00')) {
return $fallback;
}
try {
$carbon = $value instanceof Carbon ? $value->copy() : Carbon::parse($value);
if ($carbon->year < 1000 || $carbon->year > 3000) {
return $fallback;
}
return $carbon->format('Y-m-d');
} catch (Throwable $e) {
return $fallback;
}
}
}