From 030bfa73fd4fb85f0ba2e3734c778a26abe466a7 Mon Sep 17 00:00:00 2001 From: congerh Date: Sun, 27 Oct 2024 13:05:26 +0800 Subject: [PATCH 1/2] Fix conversion of timestamps in 3 decimal places --- LrcParser/Parser/Lrc/Utils/LrcStartTimeUtils.cs | 1 + LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/LrcParser/Parser/Lrc/Utils/LrcStartTimeUtils.cs b/LrcParser/Parser/Lrc/Utils/LrcStartTimeUtils.cs index 3039b93..92e199b 100644 --- a/LrcParser/Parser/Lrc/Utils/LrcStartTimeUtils.cs +++ b/LrcParser/Parser/Lrc/Utils/LrcStartTimeUtils.cs @@ -47,6 +47,7 @@ internal static int ConvertTimeTagToMillionSecond(string timeTag) int minutes = int.Parse(match.Groups[1].Value); int seconds = int.Parse(match.Groups[2].Value); int hundredths = int.Parse(match.Groups[3].Value); + hundredths = (hundredths < 100) ? hundredths : (hundredths / 10); return minutes * 60 * 1000 + seconds * 1000 + hundredths * 10; } diff --git a/LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs b/LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs index 1f418ec..dac9e82 100644 --- a/LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs +++ b/LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs @@ -77,6 +77,7 @@ internal static int ConvertTimeTagToMillionSecond(string timeTag) int minutes = int.Parse(match.Groups[1].Value); int seconds = int.Parse(match.Groups[2].Value); int hundredths = int.Parse(match.Groups[3].Value); + hundredths = (hundredths < 100) ? hundredths : (hundredths / 10); return minutes * 60 * 1000 + seconds * 1000 + hundredths * 10; } From c176d9c8d373ee8b51b264939d1308a37ffd2d67 Mon Sep 17 00:00:00 2001 From: congerh Date: Sun, 27 Oct 2024 13:14:29 +0800 Subject: [PATCH 2/2] Add timestamps conversion test --- LrcParser.Tests/Parser/Lrc/Utils/LrcStartTimeUtilsTest.cs | 1 + LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/LrcParser.Tests/Parser/Lrc/Utils/LrcStartTimeUtilsTest.cs b/LrcParser.Tests/Parser/Lrc/Utils/LrcStartTimeUtilsTest.cs index 8a97058..7706b61 100644 --- a/LrcParser.Tests/Parser/Lrc/Utils/LrcStartTimeUtilsTest.cs +++ b/LrcParser.Tests/Parser/Lrc/Utils/LrcStartTimeUtilsTest.cs @@ -43,6 +43,7 @@ public void TestDecodeWithInvalidLine(string line, int[] expectedStartTimes, str [TestCase("[01:00.00]", 60000)] [TestCase("[10:00.00]", 600000)] [TestCase("[100:00.00]", 6000000)] + [TestCase("[12:34.567]", 754560)] [TestCase("[0:00.00]", 0)] // prevent throw error in some invalid format. [TestCase("[0:0.0]", 0)] // prevent throw error in some invalid format. [TestCase("[1:00.00][1:02.00]", 60000)] // rarely to get this case, so return the first one. diff --git a/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs b/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs index 464f71b..1c30c88 100644 --- a/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs +++ b/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs @@ -42,6 +42,7 @@ public void TestDecodeWithInvalidFormat(string text, string expectedText, string [TestCase("<01:00.00>", 60000)] [TestCase("<10:00.00>", 600000)] [TestCase("<100:00.00>", 6000000)] + [TestCase("<12:34.567>", 754560)] [TestCase("<0:00.00>", 0)] // prevent throw error in some invalid format. [TestCase("<0:0.0>", 0)] // prevent throw error in some invalid format. [TestCase("<1:00.00><1:02.00>", 60000)] // rarely to get this case, so return the first one.