Skip to content

Commit

Permalink
[9.x] Add Conditionable Trait to Illuminate\Support\Carbon (laravel#4…
Browse files Browse the repository at this point in the history
…2500)

* Make Carbon conditionable

* Style
  • Loading branch information
ralphjsmit authored and chu121su12 committed May 26, 2022
1 parent 13ad691 commit 3b9c8b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Support/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Carbon\Carbon as BaseCarbon;
use Carbon\CarbonImmutable as BaseCarbonImmutable;
use Illuminate\Support\Traits\Conditionable;

class Carbon extends BaseCarbon
{
use Conditionable;

/**
* {@inheritdoc}
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportCarbonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ public function testSetTestNowWillPersistBetweenImmutableAndMutableInstance()
$this->assertSame('2017-06-27 13:14:15', BaseCarbon::now()->toDateTimeString());
$this->assertSame('2017-06-27 13:14:15', BaseCarbonImmutable::now()->toDateTimeString());
}

public function testCarbonIsConditionable()
{
$this->assertTrue(Carbon::now()->when(null, fn (Carbon $carbon) => $carbon->addDays(1))->isToday());
$this->assertTrue(Carbon::now()->when(true, fn (Carbon $carbon) => $carbon->addDays(1))->isTomorrow());
}
}

0 comments on commit 3b9c8b0

Please sign in to comment.