Skip to content

Commit 0ec3e78

Browse files
[9.x] Use CarbonImmutable by default (#38258)
* Ensure that Illuminate\Support\Carbon is used consistently across the framework * Update tests to support immutable dates by default * Update date calls to support immutable-first behaviour * cs fixes * Per PR review, revert to using Carbon by default
1 parent 13e4a7f commit 0ec3e78

File tree

10 files changed

+12
-13
lines changed

10 files changed

+12
-13
lines changed

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ protected function expressionPasses()
324324
$date = Date::now();
325325

326326
if ($this->timezone) {
327-
$date->setTimezone($this->timezone);
327+
$date = $date->setTimezone($this->timezone);
328328
}
329329

330330
return (new CronExpression($this->expression))->isDue($date->toDateTimeString());

src/Illuminate/Console/Scheduling/ManagesFrequencies.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ private function inTimeInterval($startTime, $endTime)
6060

6161
if ($endTime->lessThan($startTime)) {
6262
if ($startTime->greaterThan($now)) {
63-
$startTime->subDay(1);
63+
$startTime = $startTime->subDay(1);
6464
} else {
65-
$endTime->addDay(1);
65+
$endTime = $endTime->addDay(1);
6666
}
6767
}
6868

src/Illuminate/Foundation/Testing/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Illuminate\Foundation\Testing;
44

5-
use Carbon\Carbon;
65
use Carbon\CarbonImmutable;
76
use Illuminate\Console\Application as Artisan;
87
use Illuminate\Database\Eloquent\Model;
98
use Illuminate\Queue\Queue;
9+
use Illuminate\Support\Carbon;
1010
use Illuminate\Support\Facades\Facade;
1111
use Illuminate\Support\Facades\ParallelTesting;
1212
use Illuminate\Support\Str;

src/Illuminate/Queue/Console/PruneBatchesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Illuminate\Queue\Console;
44

5-
use Carbon\Carbon;
65
use Illuminate\Bus\BatchRepository;
76
use Illuminate\Bus\DatabaseBatchRepository;
87
use Illuminate\Bus\PrunableBatchRepository;
98
use Illuminate\Console\Command;
9+
use Illuminate\Support\Carbon;
1010

1111
class PruneBatchesCommand extends Command
1212
{

src/Illuminate/Queue/Console/PruneFailedJobsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Illuminate\Queue\Console;
44

5-
use Carbon\Carbon;
65
use Illuminate\Console\Command;
76
use Illuminate\Queue\Failed\PrunableFailedJobProvider;
7+
use Illuminate\Support\Carbon;
88

99
class PruneFailedJobsCommand extends Command
1010
{

tests/Database/DatabaseEloquentIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,8 @@ public function testIsAfterRetrievingTheSameModel()
13741374

13751375
public function testFreshMethodOnModel()
13761376
{
1377-
$now = Carbon::now();
1378-
$nowSerialized = $now->startOfSecond()->toJSON();
1377+
$now = Carbon::now()->startOfSecond();
1378+
$nowSerialized = $now->toJSON();
13791379
$nowWithFractionsSerialized = $now->toJSON();
13801380
Carbon::setTestNow($now);
13811381

tests/Pagination/CursorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Illuminate\Tests\Pagination;
44

5-
use Carbon\Carbon;
65
use Illuminate\Pagination\Cursor;
6+
use Illuminate\Support\Carbon;
77
use PHPUnit\Framework\TestCase;
88

99
class CursorTest extends TestCase

tests/Queue/QueueSqsQueueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testDelayedPushWithDateTimeProperlyPushesJobOntoSqs()
9494
$queue = $this->getMockBuilder(SqsQueue::class)->onlyMethods(['createPayload', 'secondsUntil', 'getQueue'])->setConstructorArgs([$this->sqs, $this->queueName, $this->account])->getMock();
9595
$queue->setContainer($container = m::spy(Container::class));
9696
$queue->expects($this->once())->method('createPayload')->with($this->mockedJob, $this->queueName, $this->mockedData)->willReturn($this->mockedPayload);
97-
$queue->expects($this->once())->method('secondsUntil')->with($now)->willReturn(5);
97+
$queue->expects($this->once())->method('secondsUntil')->with($now->addSeconds(5))->willReturn(5);
9898
$queue->expects($this->once())->method('getQueue')->with($this->queueName)->willReturn($this->queueUrl);
9999
$this->sqs->shouldReceive('sendMessage')->once()->with(['QueueUrl' => $this->queueUrl, 'MessageBody' => $this->mockedPayload, 'DelaySeconds' => 5])->andReturn($this->mockedSendMessageResponseModel);
100100
$id = $queue->later($now->addSeconds(5), $this->mockedJob, $this->mockedData, $this->queueName);

tests/Support/SupportCarbonTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use BadMethodCallException;
66
use Carbon\Carbon as BaseCarbon;
77
use Carbon\CarbonImmutable as BaseCarbonImmutable;
8-
use DateTime;
98
use DateTimeInterface;
109
use Illuminate\Support\Carbon;
1110
use PHPUnit\Framework\TestCase;
@@ -34,7 +33,7 @@ protected function tearDown(): void
3433

3534
public function testInstance()
3635
{
37-
$this->assertInstanceOf(DateTime::class, $this->now);
36+
$this->assertInstanceOf(Carbon::class, $this->now);
3837
$this->assertInstanceOf(DateTimeInterface::class, $this->now);
3938
$this->assertInstanceOf(BaseCarbon::class, $this->now);
4039
$this->assertInstanceOf(Carbon::class, $this->now);

tests/Support/SupportLazyCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Illuminate\Tests\Support;
44

5-
use Carbon\Carbon;
5+
use Illuminate\Support\Carbon;
66
use Illuminate\Support\Collection;
77
use Illuminate\Support\LazyCollection;
88
use Mockery as m;

0 commit comments

Comments
 (0)