Add DateTime support to database binding layer.

Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
Taylor Otwell
2012-04-10 15:03:42 -05:00
parent 7d5b6b3748
commit 94b8582865
7 changed files with 32 additions and 15 deletions

View File

@@ -193,7 +193,7 @@ abstract class Model {
{
$model = new static(array(), true);
if (static::$timestamps) $attributes['updated_at'] = $model->get_timestamp();
if (static::$timestamps) $attributes['updated_at'] = new \DateTime;
return $model->query()->where($model->key(), '=', $id)->update($attributes);
}
@@ -405,21 +405,11 @@ abstract class Model {
*/
protected function timestamp()
{
$this->updated_at = static::get_timestamp();
$this->updated_at = new \DateTime;
if ( ! $this->exists) $this->created_at = $this->updated_at;
}
/**
* Get the current timestamp in its storable form.
*
* @return mixed
*/
public static function get_timestamp()
{
return date('Y-m-d H:i:s');
}
/**
* Get a new fluent query builder instance for the model.
*

View File

@@ -204,7 +204,7 @@ class Has_Many_And_Belongs_To extends Relationship {
{
if (Pivot::$timestamps)
{
$attributes['created_at'] = $this->model->get_timestamp();
$attributes['created_at'] = new \DateTime;
$attributes['updated_at'] = $attributes['created_at'];
}

View File

@@ -29,7 +29,7 @@ class Has_One_Or_Many extends Relationship {
{
if ($this->model->timestamps())
{
$attributes['updated_at'] = $this->model->get_timestamp();
$attributes['updated_at'] = new \DateTime;
}
return $this->table->update($attributes);