From 44a44c9b7d41f01c56850085ffbbffa6c15b7888 Mon Sep 17 00:00:00 2001 From: Lex de Willigen Date: Thu, 4 Jan 2024 13:45:11 +0100 Subject: [PATCH] Support MongoDB DateTime columns --- src/ORM/Table.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ORM/Table.php b/src/ORM/Table.php index 7b3687c..db24ae0 100644 --- a/src/ORM/Table.php +++ b/src/ORM/Table.php @@ -7,7 +7,6 @@ use Cake\Chronos\ChronosInterface; use Cake\Datasource\EntityInterface; use Cake\Datasource\Exception\InvalidPrimaryKeyException; -use Cake\I18n\FrozenTime; use Cake\ORM\RulesChecker; use Cake\ORM\Table as CakeTable; use RuntimeException; @@ -214,13 +213,11 @@ protected function _processSave($entity, $options) $data = $entity->toArray(); $isNew = $entity->isNew(); - if (!isset($data['created'])) { - $data['created'] = FrozenTime::now()->toIso8601String(); - } else { - $data['created'] = FrozenTime::parse($data['created'])->toIso8601String(); + if (isset($data['created'])) { + $data['created'] = new \MongoDB\BSON\UTCDateTime($data['created']); } if (isset($data['modified'])) { - $data['modified'] = FrozenTime::now()->toIso8601String(); + $data['modified'] = new \MongoDB\BSON\UTCDateTime($data['modified']); } if ($isNew) {