Updated config parser to use consistent formatting

This commit is contained in:
Igor Scheller 2024-04-13 14:09:52 +02:00 committed by xuwhite
parent 0155a33beb
commit cb82ad9c74
1 changed files with 5 additions and 5 deletions

View File

@ -4,7 +4,8 @@ declare(strict_types=1);
namespace Engelsystem\Models;
use Carbon\Carbon;
use DateTimeInterface;
use Engelsystem\Helpers\Carbon;
use Illuminate\Database\Query\Builder as QueryBuilder;
/**
@ -55,7 +56,7 @@ class EventConfig extends BaseModel
if (!empty($value)) {
return match ($this->getValueCast($this->name)) {
'datetime_human' => Carbon::make($value),
'datetime' => Carbon::createFromFormat(Carbon::ISO8601, $value),
'datetime' => Carbon::createFromFormat(DateTimeInterface::ATOM, $value),
default => $value,
};
}
@ -71,11 +72,10 @@ class EventConfig extends BaseModel
public function setValueAttribute(mixed $value): static
{
if (!empty($value)) {
/** @var Carbon $value */
$value = match ($this->getValueCast($this->name)) {
/** @var Carbon $value */
'datetime_human' => $value->toDateTimeString('minute'),
/** @var Carbon $value */
'datetime' => $value->toIso8601String(),
'datetime' => $value->format(DateTimeInterface::ATOM),
default => $value,
};
}