Skip to content

Commit

Permalink
Merge pull request #2 from lexdewilligen/master
Browse files Browse the repository at this point in the history
Support MongoDB DateTime columns
  • Loading branch information
ShockRaver authored Jan 4, 2024
2 parents 2a6f8de + 44a44c9 commit 7a94660
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 7a94660

Please sign in to comment.