From 25fce3df73ee1f064f506547cd54938f4747617a Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Tue, 25 Dec 2018 14:31:02 +0800 Subject: [PATCH] Change dateDifference() to date_difference() --- app/Entities/Projects/Project.php | 6 +++--- app/helpers.php | 2 +- tests/Unit/Helpers/DateDifferenceTest.php | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Entities/Projects/Project.php b/app/Entities/Projects/Project.php index 7dfc082..e64abce 100755 --- a/app/Entities/Projects/Project.php +++ b/app/Entities/Projects/Project.php @@ -234,12 +234,12 @@ class Project extends Model return '-'; } - $workDuration = dateDifference($startDate, $endDate); + $workDuration = date_difference($startDate, $endDate); if ((int) $workDuration > 365) { - return dateDifference($startDate, $endDate, '%y Year(s) %m Month(s)'); + return date_difference($startDate, $endDate, '%y Year(s) %m Month(s)'); } elseif ((int) $workDuration > 30) { - return dateDifference($startDate, $endDate, '%m Month(s) %d Day(s)'); + return date_difference($startDate, $endDate, '%m Month(s) %d Day(s)'); } return $workDuration.' Day(s)'; diff --git a/app/helpers.php b/app/helpers.php index 368fd3c..cfe933f 100755 --- a/app/helpers.php +++ b/app/helpers.php @@ -195,7 +195,7 @@ function html_link_to_route($name, $title = null, $parameters = [], $attributes * @param string $differenceFormat * @return int|string */ -function dateDifference($date1, $date2, $differenceFormat = '%a') +function date_difference($date1, $date2, $differenceFormat = '%a') { $datetime1 = date_create($date1); $datetime2 = date_create($date2); diff --git a/tests/Unit/Helpers/DateDifferenceTest.php b/tests/Unit/Helpers/DateDifferenceTest.php index 6984536..3a9625e 100644 --- a/tests/Unit/Helpers/DateDifferenceTest.php +++ b/tests/Unit/Helpers/DateDifferenceTest.php @@ -14,31 +14,31 @@ class DateDifferenceTest extends TestCase /** @test */ public function date_difference_function_exists() { - $this->assertTrue(function_exists('dateDifference')); + $this->assertTrue(function_exists('date_difference')); } /** @test */ public function date_difference_returns_days_count_by_default() { - $this->assertEquals(9, dateDifference('2018-04-01', '2018-04-10')); + $this->assertEquals(9, date_difference('2018-04-01', '2018-04-10')); } /** @test */ public function date_difference_can_returns_formatted_string() { - $this->assertEquals('9 days', dateDifference('2018-04-01', '2018-04-10', '%a days')); + $this->assertEquals('9 days', date_difference('2018-04-01', '2018-04-10', '%a days')); } /** @test */ public function date_difference_returns_proper_months_and_days_format() { // TODO: Need to fix, this should returns 1 months 9 days - $this->assertEquals('1 month 12 days', dateDifference('2018-03-01', '2018-04-10', '%m month %d days')); + $this->assertEquals('1 month 12 days', date_difference('2018-03-01', '2018-04-10', '%m month %d days')); } /** @test */ public function date_difference_returns_proper_years_months_and_days_format() { - $this->assertEquals('1 year 1 month 12 days', dateDifference('2017-03-01', '2018-04-10', '%y year %m month %d days')); + $this->assertEquals('1 year 1 month 12 days', date_difference('2017-03-01', '2018-04-10', '%y year %m month %d days')); } }