diff --git a/ATL.unit-test/Misc/UtilsTest.cs b/ATL.unit-test/Misc/UtilsTest.cs
index e22e9328..7c2fb126 100644
--- a/ATL.unit-test/Misc/UtilsTest.cs
+++ b/ATL.unit-test/Misc/UtilsTest.cs
@@ -25,6 +25,8 @@ public void Utils_FormatTime()
Assert.AreEqual("01:01:00.0", Utils.EncodeTimecode_ms(60 * 60 * 1000 + 60 * 1000));
// Display d, h, m, s and ms
Assert.AreEqual("2d 01:01:00.0", Utils.EncodeTimecode_ms(48 * 60 * 60 * 1000 + 60 * 60 * 1000 + 60 * 1000));
+ // Display m, s and ms for very long durations in MM:SS.UUUU format
+ Assert.AreEqual("2941:01.0", Utils.EncodeTimecode_ms(48 * 60 * 60 * 1000 + 60 * 60 * 1000 + 60 * 1000 + 1000, true));
}
[TestMethod]
diff --git a/ATL/Entities/LyricsInfo.cs b/ATL/Entities/LyricsInfo.cs
index 8e9eb2d0..b757623d 100644
--- a/ATL/Entities/LyricsInfo.cs
+++ b/ATL/Entities/LyricsInfo.cs
@@ -350,7 +350,7 @@ public string FormatSynchToLRC()
// Lyrics
foreach (var line in SynchronizedLyrics)
{
- sb.Append('[').Append(Utils.EncodeTimecode_ms(line.TimestampMs)).Append(']').Append(line.Text).Append('\n');
+ sb.Append('[').Append(Utils.EncodeTimecode_ms(line.TimestampMs, true)).Append(']').Append(line.Text).Append('\n');
}
return sb.ToString();
diff --git a/ATL/Utils/Utils.cs b/ATL/Utils/Utils.cs
index c770ebd0..e99e6161 100644
--- a/ATL/Utils/Utils.cs
+++ b/ATL/Utils/Utils.cs
@@ -45,21 +45,26 @@ public static string ProtectValue(string value)
///
/// Format the given duration using the following format
/// DDdHH:MM:SS.UUUU
+ /// OR
+ /// MM:SS.UUUU
///
/// Where
/// DD is the number of days, if applicable (i.e. durations of less than 1 day won't display the "DDd" part)
/// HH is the number of hours, if applicable (i.e. durations of less than 1 hour won't display the "HH:" part)
- /// MM is the number of minutes
+ /// MM is the number of minutes, when using MMSS format, this will extend beyond two digits if necessary
/// SS is the number of seconds
/// UUUU is the number of milliseconds
///
/// Duration to format (in milliseconds)
+ /// Format in MM:SS.UUUU format. Default is false
/// Formatted duration according to the abovementioned convention
- public static string EncodeTimecode_ms(long milliseconds)
+ public static string EncodeTimecode_ms(long milliseconds, bool useMmSsFormat = false)
{
long seconds = Convert.ToInt64(Math.Floor(milliseconds / 1000.00));
+
+ var encodedString = useMmSsFormat ? EncodeMmSsTimecode_s(seconds) : EncodeTimecode_s(seconds);
- return EncodeTimecode_s(seconds) + "." + (milliseconds - seconds * 1000);
+ return encodedString + "." + (milliseconds - seconds * 1000);
}
///
@@ -93,6 +98,29 @@ public static string EncodeTimecode_s(long seconds)
if (h > 0) return hStr + ":" + mStr + ":" + sStr;
return mStr + ":" + sStr;
}
+
+ ///
+ /// Format the given duration using the following format
+ /// MM:SS
+ ///
+ /// Where
+ /// MM is the number of minutes, this will extend beyond two digits if necessary
+ /// SS is the number of seconds
+ ///
+ /// Duration to format (in seconds)
+ /// Formatted duration according to the abovementioned convention
+ public static string EncodeMmSsTimecode_s(long seconds)
+ {
+ var m = Convert.ToInt64(Math.Floor(seconds / 60.00));
+ var s = seconds - 60 * m;
+
+ var mStr = m.ToString();
+ if (1 == mStr.Length) mStr = "0" + mStr;
+ var sStr = s.ToString();
+ if (1 == sStr.Length) sStr = "0" + sStr;
+
+ return mStr + ":" + sStr;
+ }
///
/// Convert the duration of the given timecode to milliseconds