Skip to content

Commit

Permalink
[9.x] Add Conditionable Trait to Illuminate\Support\Carbon (#42500)
Browse files Browse the repository at this point in the history
* Make Carbon conditionable

* Style
  • Loading branch information
ralphjsmit committed May 25, 2022
1 parent 105037b commit f9fda99
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 f9fda99

Please sign in to comment.