diff --git a/app/Restify/Repository.php b/app/Restify/Repository.php index bd19fd1ac..e3bd26b19 100644 --- a/app/Restify/Repository.php +++ b/app/Restify/Repository.php @@ -23,6 +23,7 @@ use Illuminate\Support\Str; use function in_array; use function is_array; use Nette\Utils\Json; +use function is_string; /** * @phpstan-type MatchType 'text'|'string'|'bool'|'int'|'integer'|'datetime'|'between'|'array' @@ -356,7 +357,7 @@ abstract class Repository extends RestifyRepository // Fix dates (JSONAPI uses ISO 8601, DB uses Y-m-d H:i:s) $attributes = array_map( static function ($value) { - if (is_string($value) && Carbon::hasFormat($value, 'Y-m-d\TH:i:sP')) { + if (is_string($value) && (Carbon::hasFormat($value, 'Y-m-d\TH:i:sP') || Carbon::hasFormat($value, 'Y-m-d\TH:i:s.v\Z'))) { try { return Carbon::parse($value)->format('Y-m-d H:i:s'); } catch (InvalidFormatException) { diff --git a/resources/ts/Models/Model.ts b/resources/ts/Models/Model.ts index 0d360c6ad..ad122e06a 100644 --- a/resources/ts/Models/Model.ts +++ b/resources/ts/Models/Model.ts @@ -82,9 +82,11 @@ export default abstract class Model(attributeName: AN, value: ValueOf) { const date = dayjs(value as string | Date | undefined); // @ts-expect-error + // eslint-disable-next-line @typescript-eslint/no-unsafe-call if (this.isDateAttribute(attributeName) && date.isValid()) { - // @ts-expect-error - value = date.format((this as Model).constructor.dates[attributeName]); + const format = this.constructor.dates[attributeName as string]; + // eslint-disable-next-line no-param-reassign + value = (format === 'YYYY-MM-DDTHH:mm:ss.ssssssZ' ? date.toISOString() : date.format(format)) as ValueOf; } // @ts-expect-error — This is needed to parse the dates correctly. // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access