Skip to content

Commit

Permalink
Fix exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Mar 21, 2024
1 parent 189f3f6 commit 61005fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Code/Converters/SmiConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public function internalFormatToFileContent(array $internal_format , array $opti
*/
protected static function timeToInternal($format_time)
{
$format_time = str_replace('ms', '', $format_time);
if (!is_numeric($format_time)) {
throw new \Exception('Not numeric: ' . $format_time);
}
$time = $format_time / 1000;
if ($time < 0) {
$time = 0;
Expand Down
15 changes: 15 additions & 0 deletions tests/formats/SmiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ public function testNegativeTime()
$this->assertInternalFormatsEqual($expected, $actual);
}

public function testMsNearTimestamp()
{
$actual = Subtitles::loadFromString('
<SAMI>
<BODY>
<SYNC Start="1000ms"><P Class=ENUSCC>a</P></SYNC>
</BODY>
</SAMI>
')->getInternalFormat();
$expected = (new Subtitles())
->add(1, 2, 'a')
->getInternalFormat();
$this->assertInternalFormatsEqual($expected, $actual);
}

public function testNoP()
{
$actual = Subtitles::loadFromString('
Expand Down

0 comments on commit 61005fc

Please sign in to comment.