Skip to content

Commit

Permalink
datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
Eelco Bogers committed Apr 13, 2023
1 parent a5e0be6 commit f92b15f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ An Mongodb datasource for CakePHP 3.5
Install [composer](http://getcomposer.org) and run:

```bash
composer require giginc/mongodb 1.0.0
composer require shockraver/mongodb
```

## Connecting the Plugin to your application
Expand Down
9 changes: 3 additions & 6 deletions src/ORM/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 @@ -213,15 +214,11 @@ protected function _processSave($entity, $options)
$data = $entity->toArray();
$isNew = $entity->isNew();

//convert to mongodate
/** @var ChronosInterface $c */
if (isset($data['created'])) {
$c = $data['created'];
$data['created'] = new \MongoDB\BSON\UTCDateTime(strtotime($c->toDateTimeString()));
$data['created'] = FrozenTime::now()->toIso8601String();
}
if (isset($data['modified'])) {
$c = $data['modified'];
$data['modified'] = new \MongoDB\BSON\UTCDateTime(strtotime($c->toDateTimeString()));
$data['modified'] = FrozenTime::now()->toIso8601String();
}

if ($isNew) {
Expand Down

0 comments on commit f92b15f

Please sign in to comment.