Skip to content

Commit

Permalink
Add timestamps in 00.00.00.00 format
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Nov 8, 2024
1 parent e8d6514 commit 5a0be3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Code/Converters/TxtConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions tests/formats/TxtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 5a0be3d

Please sign in to comment.