Skip to content

Commit

Permalink
Ignore missing $days property when comparing copies
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Jul 16, 2024
1 parent b38436e commit c83565c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/Carbon/CarbonInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,6 @@ class CarbonInterval extends DateInterval implements CarbonConverterInterface

protected ?array $initialValues = null;

/**
* Total number of days the interval spans. If this is unknown, days will be FALSE.
* @var int|false
*/
private $days = false;

/**
* Set the instance's timezone from a string or object.
*/
Expand All @@ -315,15 +309,13 @@ public function setTimezone(DateTimeZone|string|int $timezone): static
->avoidMutation()
->setTimezone($timezone);
$this->rawInterval = null;
$this->days = false;
}

if ($this->endDate) {
$this->endDate = $this->endDate
->avoidMutation()
->setTimezone($timezone);
$this->rawInterval = null;
$this->days = false;
}

return $this;
Expand All @@ -342,15 +334,13 @@ public function shiftTimezone(DateTimeZone|string|int $timezone): static
->avoidMutation()
->shiftTimezone($timezone);
$this->rawInterval = null;
$this->days = false;
}

if ($this->endDate) {
$this->endDate = $this->endDate
->avoidMutation()
->shiftTimezone($timezone);
$this->rawInterval = null;
$this->days = false;
}

return $this;
Expand Down Expand Up @@ -801,7 +791,6 @@ public function optimize(): static
$this->startDate = null;
$this->endDate = null;
$this->rawInterval = null;
$this->days = false;

return $this;
}
Expand Down Expand Up @@ -1116,7 +1105,6 @@ public static function diff($start, $end = null, bool $absolute = false, array $
$interval = static::instance($rawInterval, $skip);

$interval->rawInterval = $rawInterval;
$interval->days = $rawInterval->days;
$interval->startDate = $start;
$interval->endDate = $end;
$interval->initialValues = $interval->getInnerValues();
Expand Down Expand Up @@ -1356,7 +1344,6 @@ public function __get(string $name): int|float|string|null
*/
public function set($name, $value = null): static
{
$this->days = false;
$properties = \is_array($name) ? $name : [$name => $value];

foreach ($properties as $key => $value) {
Expand Down Expand Up @@ -3353,7 +3340,6 @@ private function checkStartAndEnd(): void
$this->startDate = null;
$this->endDate = null;
$this->rawInterval = null;
$this->days = false;
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/CarbonInterval/ConstructTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,18 @@ public function testFromSerialization()

// Ignore translator for the English comparison
$copy->setLocalTranslator($interval->getLocalTranslator());
(function () {
$this->days ??= false;
})->call($copy);

$this->assertEquals($interval, $copy);

$interval = $today->locale('ja')->diffAsCarbonInterval($past);
/** @var CarbonInterval $copy */
$copy = unserialize(serialize($interval));
(function () {
$this->days ??= false;
})->call($copy);

$this->assertInstanceOf(CarbonInterval::class, $copy);

Expand Down

0 comments on commit c83565c

Please sign in to comment.