edit delay and penalty calculations
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
use Throwable;
|
||||
|
||||
class JalaliHelper
|
||||
{
|
||||
public static function fromDateTime($value): ?Jalalian
|
||||
{
|
||||
if ($value === null || $value === '' || $value === '0000-00-00' || str_starts_with((string) $value, '0000-00-00')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$carbon = $value instanceof Carbon ? $value : Carbon::parse($value);
|
||||
if ($carbon->year < 1000 || $carbon->year > 3000) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Jalalian::fromCarbon($carbon);
|
||||
} catch (Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function format($value, string $format = 'Y/m/d', string $fallback = '-'): string
|
||||
{
|
||||
$jalali = self::fromDateTime($value);
|
||||
|
||||
return $jalali ? $jalali->format($format) : $fallback;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user