Skip to content

Commit

Permalink
Support MongoDB DateTime columns
Browse files Browse the repository at this point in the history
  • Loading branch information
lexdewilligen committed Jan 4, 2024
1 parent 2a6f8de commit 44a44c9
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/ORM/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 44a44c9

Please sign in to comment.