1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Parse plain numbers as millisecond count when parsing timestamp

This commit is contained in:
Bartłomiej Dach 2024-06-18 16:46:47 +02:00
parent 623055b60a
commit 7ee29667db
No known key found for this signature in database
2 changed files with 11 additions and 4 deletions

View File

@ -13,9 +13,9 @@ namespace osu.Game.Tests.Editing
private static readonly object?[][] test_cases =
{
new object?[] { ":", false, null, null },
new object?[] { "1", true, new TimeSpan(0, 0, 1, 0), null },
new object?[] { "99", true, new TimeSpan(0, 0, 99, 0), null },
new object?[] { "3000", false, null, null },
new object?[] { "1", true, TimeSpan.FromMilliseconds(1), null },
new object?[] { "99", true, TimeSpan.FromMilliseconds(99), null },
new object?[] { "320000", true, TimeSpan.FromMilliseconds(320000), null },
new object?[] { "1:2", true, new TimeSpan(0, 0, 1, 2), null },
new object?[] { "1:02", true, new TimeSpan(0, 0, 1, 2), null },
new object?[] { "1:92", false, null, null },

View File

@ -32,10 +32,17 @@ namespace osu.Game.Rulesets.Edit
/// <item>1:02:300 (1,2,3) - parses to 01:02:300 with selection</item>
/// </list>
/// </example>
private static readonly Regex time_regex_lenient = new Regex(@"^(((?<minutes>\d{1,3})(:(?<seconds>([0-5]?\d))([:.](?<milliseconds>\d{0,3}))?)?)(?<selection>\s\([^)]+\))?)$", RegexOptions.Compiled);
private static readonly Regex time_regex_lenient = new Regex(@"^(((?<minutes>\d{1,3}):(?<seconds>([0-5]?\d))([:.](?<milliseconds>\d{0,3}))?)(?<selection>\s\([^)]+\))?)$", RegexOptions.Compiled);
public static bool TryParse(string timestamp, [NotNullWhen(true)] out TimeSpan? parsedTime, out string? parsedSelection)
{
if (double.TryParse(timestamp, out double msec))
{
parsedTime = TimeSpan.FromMilliseconds(msec);
parsedSelection = null;
return true;
}
Match match = time_regex_lenient.Match(timestamp);
if (!match.Success)