diff --git a/src/Code/Converters/TtmlConverter.php b/src/Code/Converters/TtmlConverter.php
index a76ac31..164665e 100644
--- a/src/Code/Converters/TtmlConverter.php
+++ b/src/Code/Converters/TtmlConverter.php
@@ -12,7 +12,7 @@ public function canParseFileContent($file_content)
public function fileContentToInternalFormat($file_content)
{
$dom = new \DOMDocument();
- $dom->loadXML($file_content);
+ @$dom->loadXML($file_content);
$array = array();
@@ -120,12 +120,14 @@ protected static function ttmlTimeToInternal($ttml_time)
} elseif (substr($ttml_time, -1) === 's') {
return rtrim($ttml_time, 's');
} else {
- $timeParts = explode(':', $ttml_time);
- $hours = (int)$timeParts[0];
- $minutes = (int)$timeParts[1];
- $seconds = (int)$timeParts[2];
- $totalSeconds = ($hours * 3600) + ($minutes * 60) + $seconds;
- return $totalSeconds;
+ $time_parts = explode('.', $ttml_time);
+ $milliseconds = 0;
+ if (isset($time_parts[1])) {
+ $milliseconds = (float) ('0.' . $time_parts[1]);
+ }
+
+ list($hours, $minutes, $seconds) = array_map('intval', explode(':', $time_parts[0]));
+ return ($hours * 3600) + ($minutes * 60) + $seconds + $milliseconds;
}
}
}
\ No newline at end of file
diff --git a/tests/files/ttml_with_duplicated_element_ids.ttml b/tests/files/ttml_with_duplicated_element_ids.ttml
new file mode 100644
index 0000000..8d68c00
--- /dev/null
+++ b/tests/files/ttml_with_duplicated_element_ids.ttml
@@ -0,0 +1,21 @@
+
+
+
+ TTML Example With Duplicated Element Ids
+ Thierry Michel 2015
+
+
+
+
+
+
+
+
+
First line.
+
Second line.
+
Third line.
+
+
+
\ No newline at end of file
diff --git a/tests/files/ttml_with_mixed_timestamps.ttml b/tests/files/ttml_with_mixed_timestamps.ttml
new file mode 100644
index 0000000..b97b062
--- /dev/null
+++ b/tests/files/ttml_with_mixed_timestamps.ttml
@@ -0,0 +1,22 @@
+
+
+
+ TTML Example Mixed Timestamp formats
+ Thierry Michel 2015
+
+
+
+
+
+
+
+
+
+
First line.
+
Second line.
+
Third line.
+
+
+
\ No newline at end of file
diff --git a/tests/formats/TtmlTest.php b/tests/formats/TtmlTest.php
index 8505c3e..44bde6e 100644
--- a/tests/formats/TtmlTest.php
+++ b/tests/formats/TtmlTest.php
@@ -63,4 +63,28 @@ public function testParses2()
$this->assertInternalFormatsEqual($expected, $actual);
}
+ public function testDifferentTimestampParse()
+ {
+ $ttml_path = './tests/files/ttml_with_mixed_timestamps.ttml';
+ $actual = Subtitles::loadFromFile($ttml_path)->getInternalFormat();
+ $expected = (new Subtitles())
+ ->add(0, 10, 'First line.')
+ ->add(11.2, 13.3, ['Second line.'])
+ ->add(15, 18, ['Third line.'])
+ ->getInternalFormat();
+ $this->assertInternalFormatsEqual($expected, $actual);
+ }
+
+ public function testDuplicatedElementIdsParse()
+ {
+ $ttml_path = './tests/files/ttml_with_duplicated_element_ids.ttml';
+ $actual = Subtitles::loadFromFile($ttml_path)->getInternalFormat();
+ $expected = (new Subtitles())
+ ->add(0, 1, 'First line.')
+ ->add(1, 2, ['Second line.'])
+ ->add(2, 3, ['Third line.'])
+ ->getInternalFormat();
+ $this->assertInternalFormatsEqual($expected, $actual);
+ }
+
}
\ No newline at end of file