Skip to content

Commit

Permalink
Using icanboogie/datetime v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 8, 2016
1 parent 16e8d7b commit b9d1cf1
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 71 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ The `EXTENDING` attribute specifies the model to extend.

use ICanBoogie\ActiveRecord\Model;
use ICanBoogie\ActiveRecord\ModelCollection;
use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/* @var $connections \ICanBoogie\ActiveRecord\ConnectionCollection */

Expand Down Expand Up @@ -480,7 +480,7 @@ $models['news']->save([

'title' => "Testing!",
'body' => "Testing...",
'date' => DateTime::now()
'date' => ImmutableDateTime::now()

]);
```
Expand Down Expand Up @@ -837,7 +837,7 @@ $record->delete();

The package comes with three trait properties especially designed to handle [DateTime][]
instances: [DateTimeProperty][], [CreatedAtProperty][], [UpdatedAtProperty][]. Using this
properties you are guaranteed to always get a [DateTime][] instance, no matter what value type
properties you are guaranteed to always get a [ImmutableDateTime][] instance, no matter what value type
is used to set the date and time.

```php
Expand All @@ -859,7 +859,7 @@ class Node extends ActiveRecord

$node = new Node;

echo get_class($node->created_at); // ICanBoogie\Datetime
echo get_class($node->created_at); // ICanBoogie\ImmutableDateTime
echo $node->created_at->is_empty; // true
$node->created_at = 'now';
echo $node->created_at; // 2014-02-21T15:00:00+0100
Expand Down Expand Up @@ -2526,7 +2526,8 @@ The package is continuously tested by [Travis CI](http://about.travis-ci.org/).
[StatementNotValid]: http://api.icanboogie.org/activerecord/4.0/class-ICanBoogie.ActiveRecord.StatementNotValid.html
[UnableToSetFetchMode]: http://api.icanboogie.org/activerecord/4.0/class-ICanBoogie.ActiveRecord.UnableToSetFetchMode.html
[UpdatedAtProperty]: http://api.icanboogie.org/activerecord/4.0/class-ICanBoogie.ActiveRecord.Property.UpdatedAtProperty.html
[DateTime]: http://api.icanboogie.org/datetime/1.2/class-ICanBoogie.DateTime.html
[DateTime]: http://api.icanboogie.org/datetime/2.0/class-ICanBoogie.DateTime.html
[ImmutableDateTime]: http://api.icanboogie.org/datetime/2.0/class-ICanBoogie.DateTime.html
[ValidationErrors]: http://api.icanboogie.org/validate/latest/class-ICanBoogie.Validate.ValidationErrors.html
[icanboogie/bind-activerecord]: https://github.com/ICanBoogie/bind-activerecord
[ICanBoogie]: http://icanboogie.org
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ext-pdo": "*",
"icanboogie/prototype": "^3.0",
"icanboogie/inflector": "^1.4",
"icanboogie/datetime": "^1.2",
"icanboogie/datetime": "^2.0",
"icanboogie/validate": "dev-master"
},

Expand Down
4 changes: 2 additions & 2 deletions lib/ActiveRecord/Driver/BasicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use ICanBoogie\Accessor\AccessorTrait;
use ICanBoogie\ActiveRecord\Connection;
use ICanBoogie\ActiveRecord\Driver;
use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Basic connection driver.
Expand Down Expand Up @@ -93,7 +93,7 @@ public function cast_value($value, $type = null)
{
if ($value instanceof \DateTimeInterface)
{
$value = DateTime::from($value);
$value = ImmutableDateTime::from($value);

return $value->utc->as_db;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Property/CreatedAtProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Implements a `created_at` property.
*
* @see DateTimeProperty
*
* @property DateTime $created_at
* @property ImmutableDateTime $created_at
*/
trait CreatedAtProperty
{
Expand All @@ -32,7 +32,7 @@ trait CreatedAtProperty
/**
* Returns the date and time at which the record was created.
*
* @return DateTime
* @return ImmutableDateTime
*/
protected function get_created_at()
{
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Property/DateProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Implements a `date` property.
*
* @property DateTime $date
* @property ImmutableDateTime $date
*
* @codeCoverageIgnore
*/
Expand All @@ -32,7 +32,7 @@ trait DateProperty
/**
* Returns the date.
*
* @return DateTime
* @return ImmutableDateTime
*/
protected function get_date()
{
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Property/DateTimeProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Implements a `datetime` property.
*
* @property DateTime $datetime
* @property ImmutableDateTime $datetime
*/
trait DateTimeProperty
{
Expand All @@ -30,7 +30,7 @@ trait DateTimeProperty
/**
* Returns the date and time.
*
* @return DateTime
* @return ImmutableDateTime
*/
protected function get_datetime()
{
Expand Down
12 changes: 7 additions & 5 deletions lib/ActiveRecord/Property/DateTimePropertySupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Provides support for datetime properties.
Expand All @@ -26,23 +26,25 @@ class DateTimePropertySupport
*/
static public function set(&$property, $datetime)
{
$property = $datetime === 'now' ? DateTime::now() : $datetime;
$property = $datetime === 'now' ? ImmutableDateTime::now() : $datetime;
}

/**
* Returns the {@link DateTime} instance of a property.
*
* @param mixed $property Reference to the property to return.
*
* @return DateTime The function always return a {@link DateTime} instance.
* @return ImmutableDateTime The function always return a {@link ImmutableDateTime} instance.
*/
static public function get(&$property)
{
if ($property instanceof DateTime)
if ($property instanceof ImmutableDateTime)
{
return $property;
}

return $property = $property === null ? DateTime::none() : new DateTime($property, 'utc');
return $property = $property === null
? ImmutableDateTime::none()
: ImmutableDateTime::from($property, 'utc');
}
}
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Property/FinishAtProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Implements a `finish_at` property.
*
* @see DateTimeProperty
*
* @property DateTime $finish_at
* @property ImmutableDateTime $finish_at
*
* @codeCoverageIgnore
*/
Expand All @@ -34,7 +34,7 @@ trait FinishAtProperty
/**
* Returns the date and time at which the record was finish.
*
* @return DateTime
* @return ImmutableDateTime
*/
protected function get_finish_at()
{
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Property/FinishedAtProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Implements a `finished_at` property.
*
* @see DateTimeProperty
*
* @property DateTime $finished_at
* @property ImmutableDateTime $finished_at
*
* @codeCoverageIgnore
*/
Expand All @@ -34,7 +34,7 @@ trait FinishedAtProperty
/**
* Returns the date and time at which the record was finished.
*
* @return DateTime
* @return ImmutableDateTime
*/
protected function get_finished_at()
{
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Property/StartAtProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Implements a `start_at` property.
*
* @see DateTimeProperty
*
* @property DateTime $start_at
* @property ImmutableDateTime $start_at
*
* @codeCoverageIgnore
*/
Expand All @@ -34,7 +34,7 @@ trait StartAtProperty
/**
* Returns the date and time at which the record was start.
*
* @return DateTime
* @return ImmutableDateTime
*/
protected function get_start_at()
{
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Property/StartedAtProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Implements a `started_at` property.
*
* @see DateTimeProperty
*
* @property DateTime $started_at
* @property ImmutableDateTime $started_at
*
* @codeCoverageIgnore
*/
Expand All @@ -34,7 +34,7 @@ trait StartedAtProperty
/**
* Returns the date and time at which the record was started.
*
* @return DateTime
* @return ImmutableDateTime
*/
protected function get_started_at()
{
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Property/UpdatedAtProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace ICanBoogie\ActiveRecord\Property;

use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;

/**
* Implements a `updated_at` property.
*
* @see DateTimeProperty
*
* @property DateTime $updated_at
* @property ImmutableDateTime $updated_at
*/
trait UpdatedAtProperty
{
Expand All @@ -32,7 +32,7 @@ trait UpdatedAtProperty
/**
* Returns the date and time at which the record was updated.
*
* @return DateTime
* @return ImmutableDateTime
*/
protected function get_updated_at()
{
Expand Down
4 changes: 2 additions & 2 deletions lib/ActiveRecord/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace ICanBoogie\ActiveRecord;

use ICanBoogie\ActiveRecord;
use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;
use ICanBoogie\Prototype\MethodNotDefined;
use ICanBoogie\PrototypeTrait;

Expand Down Expand Up @@ -779,7 +779,7 @@ private function deferred_parse_conditions(...$conditions_and_args)
{
if ($value instanceof \DateTimeInterface)
{
$value = DateTime::from($value)->utc->as_db;
$value = ImmutableDateTime::from($value)->utc->as_db;
}
}

Expand Down
20 changes: 10 additions & 10 deletions tests/ActiveRecord/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use ICanBoogie\ActiveRecord\ModelTest\Car;
use ICanBoogie\ActiveRecord\ModelTest\Comment;
use ICanBoogie\ActiveRecord\ModelTest\Driver;
use ICanBoogie\DateTime;
use ICanBoogie\ImmutableDateTime;
use ICanBoogie\OffsetNotWritable;

class ModelTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -137,7 +137,7 @@ public function setUp()

foreach ($names as $name)
{
$counts->save([ 'name' => $name, 'date' => DateTime::now() ]);
$counts->save([ 'name' => $name, 'date' => ImmutableDateTime::now() ]);
}

$this->connections = $connections;
Expand Down Expand Up @@ -285,7 +285,7 @@ public function test_should_throw_not_found_when_all_record_do_not_exists()
public function test_find_one()
{
$model = $this->models['articles'];
$id = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => DateTime::now() ]);
$id = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => ImmutableDateTime::now() ]);
$this->assertNotEmpty($id);

$record = $model->find($id);
Expand All @@ -296,9 +296,9 @@ public function test_find_one()
public function test_find_many()
{
$model = $this->models['articles'];
$id1 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => DateTime::now() ]);
$id2 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => DateTime::now() ]);
$id3 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => DateTime::now() ]);
$id1 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => ImmutableDateTime::now() ]);
$id2 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => ImmutableDateTime::now() ]);
$id3 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => ImmutableDateTime::now() ]);
$this->assertNotEmpty($id1);
$this->assertNotEmpty($id2);
$this->assertNotEmpty($id3);
Expand All @@ -319,9 +319,9 @@ public function test_find_many()
public function test_find_many_with_an_array()
{
$model = $this->models['articles'];
$id1 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => DateTime::now() ]);
$id2 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => DateTime::now() ]);
$id3 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => DateTime::now() ]);
$id1 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => ImmutableDateTime::now() ]);
$id2 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => ImmutableDateTime::now() ]);
$id3 = $model->save([ 'title' => uniqid(), 'body' => uniqid(), 'date' => ImmutableDateTime::now() ]);
$this->assertNotEmpty($id1);
$this->assertNotEmpty($id2);
$this->assertNotEmpty($id3);
Expand Down Expand Up @@ -640,7 +640,7 @@ public function test_cache_should_be_revoked_on_save()
$name2 = uniqid();

$model = $this->counts_model;
$id = $model->save([ 'name' => $name1, 'date' => DateTime::now() ]);
$id = $model->save([ 'name' => $name1, 'date' => ImmutableDateTime::now() ]);
$record = $model[$id];
$model->save([ 'name' => $name2 ], $id);
$record_now = $model[$id];
Expand Down

0 comments on commit b9d1cf1

Please sign in to comment.