From fbf0d97003a0cdd45b471ec9315eb41d28890f96 Mon Sep 17 00:00:00 2001 From: Samuel De Backer Date: Sun, 15 Mar 2015 22:57:22 +0100 Subject: [PATCH] datetime --- src/Presenters/Presenter.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Presenters/Presenter.php b/src/Presenters/Presenter.php index 62735c1b..bbe4e1d5 100644 --- a/src/Presenters/Presenter.php +++ b/src/Presenters/Presenter.php @@ -37,6 +37,18 @@ public function __get($property) return $this->entity->{$property}; } + /** + * Return resource's datetime or curent date and time if empty + * + * @param string $column + * @return Carbon + */ + public function datetimeOrNow($column = 'date') + { + $date = $this->entity->$column ? : Carbon::now() ; + return $date->format('Y-m-d G:i:s'); + } + /** * Return resource's date or curent date if empty * @@ -58,7 +70,7 @@ public function dateOrNow($column = 'date') public function timeOrNow($column = 'date') { $date = $this->entity->$column ? : Carbon::now() ; - return $date->format('H:i'); + return $date->format('G:i'); } /**