diff --git a/IPA.Loader/Config/Stores/Converters.cs b/IPA.Loader/Config/Stores/Converters.cs index f709b2a6..b5c18a8f 100644 --- a/IPA.Loader/Config/Stores/Converters.cs +++ b/IPA.Loader/Config/Stores/Converters.cs @@ -114,7 +114,8 @@ namespace IPA.Config.Stores.Converters IValConv, IValConv, IValConv, IValConv, IValConv, IValConv, - IValConv, IValConv + IValConv, IValConv, + IValConv { internal static readonly ValConvImpls Impl = new ValConvImpls(); Type IValConv.Get() => typeof(CharConverter); @@ -134,6 +135,7 @@ namespace IPA.Config.Stores.Converters Type IValConv.Get() => typeof(BooleanConverter); Type IValConv.Get() => typeof(DateTimeConverter); Type IValConv.Get() => typeof(DateTimeOffsetConverter); + Type IValConv.Get() => typeof(TimeSpanConverter); } } @@ -698,4 +700,24 @@ namespace IPA.Config.Stores.Converters public override Value ToValue(DateTimeOffset obj, object parent) => Value.Text(obj.ToString("O")); } + + internal class TimeSpanConverter : ValueConverter + { + public override TimeSpan FromValue(Value value, object parent) + { + if (!(value is Text text)) + { + throw new ArgumentException("Value is not of type Text", nameof(value)); + } + + if (TimeSpan.TryParse(text.Value, out var dateTime)) + { + return dateTime; + } + + throw new ArgumentException($"Parsing failed, {text.Value}"); + } + + public override Value ToValue(TimeSpan obj, object parent) => Value.Text(obj.ToString()); + } }