From 61005fcee8ae63ad155b75706bf3bbbabc60558e Mon Sep 17 00:00:00 2001 From: Mantas Date: Thu, 21 Mar 2024 14:54:06 +0200 Subject: [PATCH] Fix exception --- src/Code/Converters/SmiConverter.php | 4 ++++ tests/formats/SmiTest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Code/Converters/SmiConverter.php b/src/Code/Converters/SmiConverter.php index 419c8fb..a7fab81 100644 --- a/src/Code/Converters/SmiConverter.php +++ b/src/Code/Converters/SmiConverter.php @@ -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; diff --git a/tests/formats/SmiTest.php b/tests/formats/SmiTest.php index a8dd97b..0570466 100644 --- a/tests/formats/SmiTest.php +++ b/tests/formats/SmiTest.php @@ -73,6 +73,21 @@ public function testNegativeTime() $this->assertInternalFormatsEqual($expected, $actual); } + public function testMsNearTimestamp() + { + $actual = Subtitles::loadFromString(' + + +

a

+ +
+ ')->getInternalFormat(); + $expected = (new Subtitles()) + ->add(1, 2, 'a') + ->getInternalFormat(); + $this->assertInternalFormatsEqual($expected, $actual); + } + public function testNoP() { $actual = Subtitles::loadFromString('