Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
seabasss opened this issue Feb 4, 2025 · 0 comments

Comments

@seabasss
Copy link
Contributor

seabasss commented Feb 4, 2025

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant