Skip to content

Commit ae56dac

Browse files
committed
fix: retrocompatibilité de timeToDate
1 parent 966eb69 commit ae56dac

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎src/Model.php‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,26 @@ protected function addTimestamps(array $data, string $action): array
764764
*/
765765
protected function freshTimestamp(): int|string
766766
{
767-
$now = Date::now();
767+
return $this->timeToDate(Date::now());
768+
}
768769

770+
/**
771+
* Convertit la valeur Date en chaîne en utilisant $this->dateFormat.
772+
*
773+
* Les formats disponibles sont :
774+
* - 'int' - Stocke la date sous la forme d'un horodatage entier
775+
* - 'datetime' - Stocke les données au format datetime SQL
776+
* - 'date' - Stocke la date (uniquement) au format de date SQL.
777+
*
778+
* @return int|string
779+
*/
780+
protected function timeToDate(Date $date): int|string
781+
{
769782
return match ($this->dateFormat) {
770-
'int' => $now->getTimestamp(),
771-
'date' => $now->format('Y-m-d'),
772-
default => $now->format('Y-m-d H:i:s'),
783+
'int' => $date->getTimestamp(),
784+
'date' => $date->format('Y-m-d'),
785+
'datetime' => $date->format('Y-m-d H:i:s'),
786+
default => (string) $date,
773787
};
774788
}
775789

@@ -851,7 +865,8 @@ protected function objectToArray(object $object): array
851865
$properties = [];
852866

853867
foreach ($props as $prop) {
854-
$properties[$prop->getName()] = $prop->getValue($object);
868+
$value = $prop->getValue($object);
869+
$properties[$prop->getName()] = $value instanceof Date ? $this->timeToDate($value) : $value;
855870
}
856871
}
857872

0 commit comments

Comments
 (0)