Use custom TimeSpanParser (#223)

Closes #154

---------

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
Macintxsh 2023-12-31 15:27:00 +03:00 committed by GitHub
parent 894e819865
commit e01fde83c6
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 183 additions and 16 deletions

View file

@ -1,13 +1,11 @@
using System.Text.Json.Nodes;
using Remora.Commands.Parsers;
using Octobot.Parsers;
using Remora.Results;
namespace Octobot.Data.Options;
public sealed class TimeSpanOption : Option<TimeSpan>
{
private static readonly TimeSpanParser Parser = new();
public TimeSpanOption(string name, TimeSpan defaultValue) : base(name, defaultValue) { }
public override TimeSpan Get(JsonNode settings)
@ -29,6 +27,6 @@ public sealed class TimeSpanOption : Option<TimeSpan>
private static Result<TimeSpan> ParseTimeSpan(string from)
{
return Parser.TryParseAsync(from).AsTask().GetAwaiter().GetResult();
return TimeSpanParser.TryParse(from);
}
}