diff --git a/libse/Paragraph.cs b/libse/Paragraph.cs index b33f5c91b..4e5daac4a 100644 --- a/libse/Paragraph.cs +++ b/libse/Paragraph.cs @@ -115,11 +115,8 @@ namespace Nikse.SubtitleEdit.Core if (StartTime.IsMaxTime) return; - double seconds = StartTime.TimeSpan.TotalSeconds * factor + adjustmentInSeconds; - StartTime.TimeSpan = TimeSpan.FromSeconds(seconds); - - seconds = EndTime.TimeSpan.TotalSeconds * factor + adjustmentInSeconds; - EndTime.TimeSpan = TimeSpan.FromSeconds(seconds); + StartTime.TotalMilliseconds = StartTime.TotalMilliseconds * factor + (adjustmentInSeconds * TimeCode.BaseUnit); + EndTime.TotalMilliseconds = EndTime.TotalMilliseconds * factor + (adjustmentInSeconds * TimeCode.BaseUnit); } public void CalculateFrameNumbersFromTimeCodes(double frameRate) diff --git a/src/Test/Logic/ParagraphTest.cs b/src/Test/Logic/ParagraphTest.cs index 41adb9cac..10f01de2a 100644 --- a/src/Test/Logic/ParagraphTest.cs +++ b/src/Test/Logic/ParagraphTest.cs @@ -38,17 +38,19 @@ namespace Test.Logic [TestMethod] public void TestAdjust1() { - var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0,1,1,1) }; + var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0,1,1,1), EndTime = new TimeCode(0, 1, 3, 1) }; p.Adjust(1, 10); - Assert.AreEqual(new TimeCode(0,1,11,1).TotalMilliseconds, p.StartTime.TotalMilliseconds); + Assert.AreEqual(new TimeCode(0, 1, 11, 1).TotalMilliseconds, p.StartTime.TotalMilliseconds); + Assert.AreEqual(new TimeCode(0, 1, 13, 1).TotalMilliseconds, p.EndTime.TotalMilliseconds); } [TestMethod] public void TestAdjust2() { - var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 1, 1, 1) }; + var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 1, 1, 1), EndTime = new TimeCode(0, 1, 4, 1) }; p.Adjust(2, 10); Assert.AreEqual(new TimeCode(0, 2, 12, 2).TotalMilliseconds, p.StartTime.TotalMilliseconds); + Assert.AreEqual(new TimeCode(0, 2, 18, 2).TotalMilliseconds, p.EndTime.TotalMilliseconds); } [TestMethod] @@ -59,5 +61,12 @@ namespace Test.Logic Assert.AreEqual(1, p.StartTime.TotalSeconds); } + [TestMethod] + public void TestDuration() + { + var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 1, 0, 0), EndTime = new TimeCode(0, 1, 1, 1) }; + Assert.AreEqual(p.Duration.TotalMilliseconds, 1001); + } + } }