-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Description
The Timecode class does not correctly handle Timecode instances in several places, even though the documentation explicitly states that it should.
According to the package documentation, the add() method should accept an existing Timecode object:
From the docs:
add($time, $operation = 1)
Adds a timecode or a frame count to the current Timecode object.
$time:int|string|Timecodeindicating the value to be added.
$operation:intused to get the sign of time.
return:TimecodeReference to the Timecode object.
However, the actual method signature only accepts int|string|DateTime, and trying to pass a Timecode object results in unintended behavior.
Expected Behavior
Calling add($timecodeObject) or constructing a Timecode object from another Timecode should work as described in the documentation.
Actual Behavior
Passing a Timecode object results in incorrect behavior.
Steps to Reproduce
$tc1 = new Timecode('00:01:00:00');
$tc2 = new Timecode('00:01:00:00');
// Expected: 00:02:00:00
$tc1->add($tc2)->toString();
Workaround
$tc1->add($tc2->toString())->toString();
Proposed Fix
Modify the add(), subtract(), and constructor to correctly handle Timecode instances.
Here’s an example of a fix:
public function add($time, int $operation = 1) : self
{
$operation = $operation < 0 ? -1 : 1;
if ($time instanceof self) {
$frameCount = $this->getFrameCount() + ($time->getFrameCount() * $operation);
} else {
$timeCode = new self($time, $this->getFrameRate(), $this->getDropFrame());
$frameCount = $this->getFrameCount() + ($timeCode->getFrameCount() * $operation);
}
$this->setFrameCount($frameCount);
return $this;
}
Let me know if you need more details!