diff --git a/src/Code/Converters/TxtConverter.php b/src/Code/Converters/TxtConverter.php index defcaee..0684643 100644 --- a/src/Code/Converters/TxtConverter.php +++ b/src/Code/Converters/TxtConverter.php @@ -7,7 +7,7 @@ class TxtConverter implements ConverterContract { - public static $time_regexp = '/(?:\d{2}[:;])(?:\d{1,2}[:;])(?:\d{1,2}[:;])\d{1,3}|(?:\d{1,2}[:;])?(?:\d{1,2}[:;])\d{1,3}(?:[.,]\d+)?(?!\d)|\d{1,5}[.,]\d{1,3}/'; + public static $time_regexp = '/(?:\d{2}[:.])(?:\d{2}[:.])(?:\d{2}[:.])(?:\d{2,3})|(?:\d{2}[:;])(?:\d{1,2}[:;])(?:\d{1,2}[:;])\d{1,3}|(?:\d{1,2}[:;])?(?:\d{1,2}[:;])\d{1,3}(?:[.,]\d+)?(?!\d)|\d{1,5}[.,]\d{1,3}/'; private static $any_letter_regex = '/\p{L}/u'; public function canParseFileContent($file_content, $original_file_content) @@ -335,6 +335,12 @@ public static function timeToInternal(string $time, $fps) { $time = trim($time); $time = str_replace(';', ':', $time); + + $dot_count = substr_count($time, '.'); + if ($dot_count === 3) { + $time = str_replace('.', ':', $time); + } + $time_parts = explode(':', $time); $total_parts = count($time_parts); diff --git a/tests/formats/TxtTest.php b/tests/formats/TxtTest.php index a64c34d..6b16dcf 100644 --- a/tests/formats/TxtTest.php +++ b/tests/formats/TxtTest.php @@ -170,6 +170,13 @@ public function testTimestamps() (new Subtitles())->add(1103.474, 1152.99, ',Speaker 2,""So at any time"""')->getInternalFormat(), Subtitles::loadFromString(' "00:18:23:46,00:19:12:96,Speaker 2,""So at any time""" +')->getInternalFormat()); + + $this->assertInternalFormatsEqual( + (new Subtitles())->add(3723.16, 3724.16, 'g')->getInternalFormat(), + Subtitles::loadFromString(' +01.02.03.04 +g ')->getInternalFormat()); }