From 0c1bde3906a867977998fd30452488547735bc44 Mon Sep 17 00:00:00 2001 From: Hugh Grigg Date: Sat, 29 Jun 2019 17:56:18 +0100 Subject: [PATCH 1/3] Rename floor, round and ceil methods --- src/BusinessTime.php | 6 +++--- src/Deadline/RecurringDeadline.php | 6 +++--- tests/Unit/BusinessTime/RoundTest.php | 6 +++--- tests/Unit/BusinessTime/TimeZoneTest.php | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/BusinessTime.php b/src/BusinessTime.php index f8d37b7..93d618c 100644 --- a/src/BusinessTime.php +++ b/src/BusinessTime.php @@ -404,7 +404,7 @@ public function endOfBusinessDay(): self * * @return BusinessTime */ - public function floor(DateInterval $precision = null): self + public function floorToPrecision(DateInterval $precision = null): self { $precisionSeconds = Interval::instance($precision ?: $this->precision()) ->inSeconds(); @@ -434,7 +434,7 @@ public function floor(DateInterval $precision = null): self * * @return BusinessTime */ - public function round(DateInterval $precision = null): self + public function roundToPrecision(DateInterval $precision = null): self { $precisionSeconds = Interval::instance($precision ?: $this->precision()) ->inSeconds(); @@ -467,7 +467,7 @@ public function round(DateInterval $precision = null): self * * @return BusinessTime */ - public function ceil(DateInterval $precision = null): self + public function ceilToPrecision(DateInterval $precision = null): self { $seconds = Interval::instance($precision ?: $this->precision()) ->inSeconds(); diff --git a/src/Deadline/RecurringDeadline.php b/src/Deadline/RecurringDeadline.php index 974b4d2..ef451e6 100644 --- a/src/Deadline/RecurringDeadline.php +++ b/src/Deadline/RecurringDeadline.php @@ -53,7 +53,7 @@ public function nextOccurrenceFrom(BusinessTime $time): BusinessTime $time = $time->add($time->precision()); } - return $time->floor(); + return $time->floorToPrecision(); } /** @@ -81,7 +81,7 @@ public function previousOccurrenceFrom(BusinessTime $time): BusinessTime $time = $time->sub($time->precision()); } - return $time->floor(); + return $time->floorToPrecision(); } /** @@ -125,7 +125,7 @@ public function firstTimePassedBetween( $time = $start->copy(); while ($time->lte($end)) { if ($this->isDeadline($time)) { - return $time->floor(); + return $time->floorToPrecision(); } $time = $time->add($time->precision()); } diff --git a/tests/Unit/BusinessTime/RoundTest.php b/tests/Unit/BusinessTime/RoundTest.php index c0a47ab..93f578b 100644 --- a/tests/Unit/BusinessTime/RoundTest.php +++ b/tests/Unit/BusinessTime/RoundTest.php @@ -36,7 +36,7 @@ public function testFloor( $businessTime = new BusinessTime($time); // When we floor it to a precision interval. - $floored = $businessTime->floor($precision); + $floored = $businessTime->floorToPrecision($precision); // Then we should get the expected floored time. self::assertSame( @@ -95,7 +95,7 @@ public function testRound( $businessTime = new BusinessTime($time); // When we round it to a precision interval. - $rounded = $businessTime->round($precision); + $rounded = $businessTime->roundToPrecision($precision); // Then we should get the expected rounded time. self::assertSame( @@ -154,7 +154,7 @@ public function testCeil( $businessTime = new BusinessTime($time); // When we ceil it to a precision interval. - $ceil = $businessTime->ceil($precision); + $ceil = $businessTime->ceilToPrecision($precision); // Then we should get the expected ceil-ed time. self::assertSame( diff --git a/tests/Unit/BusinessTime/TimeZoneTest.php b/tests/Unit/BusinessTime/TimeZoneTest.php index 20a38ae..8bc254c 100644 --- a/tests/Unit/BusinessTime/TimeZoneTest.php +++ b/tests/Unit/BusinessTime/TimeZoneTest.php @@ -39,7 +39,7 @@ public function testFloorToHourInTimezone(string $timezone) $businessTime = $businessTime->setTimezone($timezone); // When we floor it to the nearest hour. - $floored = $businessTime->floor(Interval::hour()); + $floored = $businessTime->floorToPrecision(Interval::hour()); // Then we should get the expected floored time. self::assertSame( @@ -73,7 +73,7 @@ public function testRoundDownToHourInTimezone(string $timezone) $businessTime = $businessTime->setTimezone($timezone); // When we round it to the nearest hour. - $floored = $businessTime->round(Interval::hour()); + $floored = $businessTime->roundToPrecision(Interval::hour()); // Then we should get the expected rounded time. self::assertSame( @@ -107,7 +107,7 @@ public function testRoundUpToHourInTimezone(string $timezone) $businessTime = $businessTime->setTimezone($timezone); // When we round it to the nearest hour. - $floored = $businessTime->round(Interval::hour()); + $floored = $businessTime->roundToPrecision(Interval::hour()); // Then we should get the expected rounded time. self::assertSame( @@ -141,7 +141,7 @@ public function testCeilDownToHourInTimezone(string $timezone) $businessTime = $businessTime->setTimezone($timezone); // When we ceil it to the nearest hour. - $floored = $businessTime->ceil(Interval::hour()); + $floored = $businessTime->ceilToPrecision(Interval::hour()); // Then we should get the expected rounded time. self::assertSame( From 51afeb1ee85dbd5b0f18053fbffe98911f8ab509 Mon Sep 17 00:00:00 2001 From: Hugh Grigg Date: Sat, 29 Jun 2019 18:00:02 +0100 Subject: [PATCH 2/3] Allow Carbon ^2.0 --- composer.json | 2 +- src/Interval.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index c2f6e12..82dcbad 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "type": "library", "require": { "php": "^7.0", - "nesbot/carbon": "^1.25" + "nesbot/carbon": "^1.2 || ^2.0" }, "require-dev": { "phpunit/phpunit": "^6.5 || ^7.4", diff --git a/src/Interval.php b/src/Interval.php index 046ea66..3bb2dd9 100644 --- a/src/Interval.php +++ b/src/Interval.php @@ -68,13 +68,23 @@ public function asMultipleOf(DateInterval $interval): float * intervals is to use whichever arbitrary units they are specified in, * leading to e.g. "480 minutes" instead of "8 hours". * + * @param bool $syntax * @param bool $short + * @param int $parts + * @param null $options * * @return string + * @throws \Exception + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function forHumans($short = false): string - { - return (new Carbon())->add($this)->diffForHumans(null, true, $short, 2); + public function forHumans( + $syntax = true, + $short = false, + $parts = 2, + $options = null + ): string { + return (new Carbon())->add($this)->diffForHumans(null, $syntax, $short, $parts); } /** From 3f3483a40a3aa8212d0ff5e775f8a8ccd1c4237c Mon Sep 17 00:00:00 2001 From: Hugh Grigg Date: Sat, 29 Jun 2019 17:00:29 +0000 Subject: [PATCH 3/3] Apply fixes from StyleCI --- src/Interval.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Interval.php b/src/Interval.php index 3bb2dd9..10c0dfb 100644 --- a/src/Interval.php +++ b/src/Interval.php @@ -73,9 +73,10 @@ public function asMultipleOf(DateInterval $interval): float * @param int $parts * @param null $options * - * @return string * @throws \Exception * + * @return string + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function forHumans(