diff --git a/IPA.Loader/Config/Stores/Converters.cs b/IPA.Loader/Config/Stores/Converters.cs index ba8b6c10..6c247dd6 100644 --- a/IPA.Loader/Config/Stores/Converters.cs +++ b/IPA.Loader/Config/Stores/Converters.cs @@ -112,7 +112,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); @@ -130,6 +131,7 @@ namespace IPA.Config.Stores.Converters Type IValConv.Get() => typeof(DoubleConverter); Type IValConv.Get() => typeof(DecimalConverter); Type IValConv.Get() => typeof(BooleanConverter); + Type IValConv.Get() => typeof(DateTimeConverter); } } @@ -618,4 +620,24 @@ namespace IPA.Config.Stores.Converters public override Value ToValue(bool obj, object parent) => Value.From(obj); } + + internal class DateTimeConverter : ValueConverter + { + public override DateTime FromValue(Value value, object parent) + { + if (!(value is Text text)) + { + throw new ArgumentException("Value is not of type Text", nameof(value)); + } + + if (DateTime.TryParse(text.Value, out var dateTime)) + { + return dateTime; + } + + throw new ArgumentException($"Parsing failed, {text.Value}"); + } + + public override Value ToValue(DateTime obj, object parent) => Value.Text(obj.ToString("O")); + } }