Skip to content

Commit

Permalink
Merge pull request #50 from hughgrigg/feature/carbon-2
Browse files Browse the repository at this point in the history
Allow Carbon ^2.0
  • Loading branch information
hughgrigg authored Jun 29, 2019
2 parents d517fc0 + f0eb226 commit 2f69b99
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/BusinessTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,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();
Expand Down Expand Up @@ -459,7 +459,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();
Expand Down Expand Up @@ -492,7 +492,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();
Expand Down
6 changes: 3 additions & 3 deletions src/Deadline/RecurringDeadline.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function nextOccurrenceFrom(BusinessTime $time): BusinessTime
$time = $time->add($time->precision());
}

return $time->floor();
return $time->floorToPrecision();
}

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ public function previousOccurrenceFrom(BusinessTime $time): BusinessTime
$time = $time->sub($time->precision());
}

return $time->floor();
return $time->floorToPrecision();
}

/**
Expand Down Expand Up @@ -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());
}
Expand Down
17 changes: 14 additions & 3 deletions src/Interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,24 @@ 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
*
* @throws \Exception
*
* @return string
*
* @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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/BusinessTime/RoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/BusinessTime/TimeZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2f69b99

Please sign in to comment.