From 60b02d5f3f7272d45f7910b85ab785fff2e01f1b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 27 Sep 2021 09:54:24 -0700 Subject: [PATCH] Revert "compare custom date/immutable_date using date comparison (#38720)" (#38993) This reverts commit cc13463ebca7325ec61810a37d5b4c0d4b3eaf29. --- .../Eloquent/Concerns/HasAttributes.php | 4 +-- .../Database/EloquentModelDateCastingTest.php | 26 ------------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 7a95842d9ddd..6ffa41f1ca75 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -1219,7 +1219,7 @@ public function getCasts() */ protected function isDateCastable($key) { - return $this->hasCast($key, ['date', 'datetime', 'custom_datetime', 'immutable_date', 'immutable_datetime', 'immutable_custom_datetime']); + return $this->hasCast($key, ['date', 'datetime', 'immutable_date', 'immutable_datetime']); } /** @@ -1645,7 +1645,7 @@ public function originalIsEquivalent($key) return true; } elseif (is_null($attribute)) { return false; - } elseif ($this->isDateAttribute($key) || $this->isDateCastable($key)) { + } elseif ($this->isDateAttribute($key)) { return $this->fromDateTime($attribute) === $this->fromDateTime($original); } elseif ($this->hasCast($key, ['object', 'collection'])) { diff --git a/tests/Integration/Database/EloquentModelDateCastingTest.php b/tests/Integration/Database/EloquentModelDateCastingTest.php index 474c5a6e508a..4a58d158b493 100644 --- a/tests/Integration/Database/EloquentModelDateCastingTest.php +++ b/tests/Integration/Database/EloquentModelDateCastingTest.php @@ -2,7 +2,6 @@ namespace Illuminate\Tests\Integration\Database\EloquentModelDateCastingTest; -use Carbon\CarbonImmutable; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Carbon; @@ -22,8 +21,6 @@ protected function setUp(): void $table->increments('id'); $table->date('date_field')->nullable(); $table->datetime('datetime_field')->nullable(); - $table->date('immutable_date_field')->nullable(); - $table->datetime('immutable_datetime_field')->nullable(); }); } @@ -39,27 +36,6 @@ public function testDatesAreCustomCastable() $this->assertInstanceOf(Carbon::class, $user->date_field); $this->assertInstanceOf(Carbon::class, $user->datetime_field); } - - public function testCustomDateCastsAreComparedAsDates() - { - /** @var TestModel1 */ - $user = TestModel1::create([ - 'date_field' => '2019-10-01', - 'datetime_field' => '2019-10-01 10:15:20', - 'immutable_date_field' => '2019-10-01', - 'immutable_datetime_field' => '2019-10-01 10:15:20', - ]); - - $user->date_field = new Carbon('2019-10-01'); - $user->datetime_field = new Carbon('2019-10-01 10:15:20'); - $user->immutable_date_field = new CarbonImmutable('2019-10-01'); - $user->immutable_datetime_field = new CarbonImmutable('2019-10-01 10:15:20'); - - $this->assertArrayNotHasKey('date_field', $user->getDirty()); - $this->assertArrayNotHasKey('datetime_field', $user->getDirty()); - $this->assertArrayNotHasKey('immutable_date_field', $user->getDirty()); - $this->assertArrayNotHasKey('immutable_datetime_field', $user->getDirty()); - } } class TestModel1 extends Model @@ -71,7 +47,5 @@ class TestModel1 extends Model public $casts = [ 'date_field' => 'date:Y-m', 'datetime_field' => 'datetime:Y-m H:i', - 'immutable_date_field' => 'date:Y-m', - 'immutable_datetime_field' => 'datetime:Y-m H:i', ]; }