Skip to content

Timecode Object Not Supported in add() and subtract() (Despite Documentation Stating Otherwise) #15

@seabasss

Description

@seabasss

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|Timecode indicating the value to be added.
$operation: int used to get the sign of time.
return: Timecode Reference 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions