mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Normalizes edge cases for parsing milliseconds.
This commit is contained in:
parent
db527e4985
commit
af54326102
@ -24,6 +24,19 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
{
|
||||
if (int.TryParse(parts[0], out var hours) && int.TryParse(parts[1], out var minutes) && int.TryParse(parts[2], out var seconds) && int.TryParse(parts[3], out var milliseconds))
|
||||
{
|
||||
// Fixes edge cases where the millisecond portion doesn't have three digits
|
||||
if (parts[3].Length < 3)
|
||||
{
|
||||
for (int msLength = parts[3].Length; msLength < 3; msLength ++)
|
||||
{
|
||||
milliseconds *= 10;
|
||||
}
|
||||
} else {
|
||||
for (int msLength = parts[3].Length; msLength > 3; msLength --)
|
||||
{
|
||||
milliseconds /= 10;
|
||||
}
|
||||
}
|
||||
return new TimeSpan(0, hours, minutes, seconds, milliseconds).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
@ -32,6 +45,19 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
{
|
||||
if (int.TryParse(parts[0], out var minutes) && int.TryParse(parts[1], out var seconds) && int.TryParse(parts[2], out var milliseconds))
|
||||
{
|
||||
// Fixes edge cases where the millisecond portion doesn't have three digits
|
||||
if (parts[3].Length < 3)
|
||||
{
|
||||
for (int msLength = parts[3].Length; msLength < 3; msLength ++)
|
||||
{
|
||||
milliseconds *= 10;
|
||||
}
|
||||
} else {
|
||||
for (int msLength = parts[3].Length; msLength > 3; msLength --)
|
||||
{
|
||||
milliseconds /= 10;
|
||||
}
|
||||
}
|
||||
return new TimeSpan(0, 0, minutes, seconds, milliseconds).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user