diff --git a/app/Entities/Projects/Project.php b/app/Entities/Projects/Project.php index d01cbfd..7dfc082 100755 --- a/app/Entities/Projects/Project.php +++ b/app/Entities/Projects/Project.php @@ -227,6 +227,21 @@ class Project extends Model public function getWorkDurationAttribute() { - return $this->present()->workDuration; + $startDate = $this->start_date; + $endDate = $this->end_date; + + if (is_null($endDate)) { + return '-'; + } + + $workDuration = dateDifference($startDate, $endDate); + + if ((int) $workDuration > 365) { + return dateDifference($startDate, $endDate, '%y Year(s) %m Month(s)'); + } elseif ((int) $workDuration > 30) { + return dateDifference($startDate, $endDate, '%m Month(s) %d Day(s)'); + } + + return $workDuration.' Day(s)'; } } diff --git a/app/Entities/Projects/ProjectPresenter.php b/app/Entities/Projects/ProjectPresenter.php index e0253e9..0678ba7 100644 --- a/app/Entities/Projects/ProjectPresenter.php +++ b/app/Entities/Projects/ProjectPresenter.php @@ -21,23 +21,4 @@ class ProjectPresenter extends Presenter { return ProjectStatus::getNameById($this->entity->status_id); } - - public function workDuration() - { - $startDate = $this->entity->start_date; - $endDate = $this->entity->end_date; - - if (is_null($endDate)) { - return '-'; - } - - $workDuration = dateDifference($startDate, $endDate); - if ((int) $workDuration > 365) { - return dateDifference($startDate, $endDate, '%y Year(s) %m Month(s) %d Day(s)'); - } elseif ((int) $workDuration > 30) { - return dateDifference($startDate, $endDate, '%m Month(s) %d Day(s)'); - } - - return $workDuration.' Day(s)'; - } } diff --git a/tests/Unit/Models/ProjectTest.php b/tests/Unit/Models/ProjectTest.php index b1af1cd..6fb19d3 100644 --- a/tests/Unit/Models/ProjectTest.php +++ b/tests/Unit/Models/ProjectTest.php @@ -229,6 +229,6 @@ class ProjectTest extends TestCase 'end_date' => '2017-07-21', ]); - $this->assertEquals('2 Year(s) 3 Month(s) 11 Day(s)', $project->work_duration); + $this->assertEquals('2 Year(s) 3 Month(s)', $project->work_duration); } }