using Connected.Extensions;

namespace Connected;

public class IsoDateConverter : Converter<DateTime, string>
{
	protected override string ConvertValue(DateTime value) => value.ToIsoDateString();

	protected override DateTime ConvertValueBack(string? value) => DateTime.TryParse(value, out var dateTime) ? dateTime : DateTime.MinValue;
}

public class NullableIsoDateConverter : Converter<DateTime?, string?>
{
	protected override string? ConvertValue(DateTime? value) => value?.ToIsoDateString();

	protected override DateTime? ConvertValueBack(string? value) => DateTime.TryParse(value, out var dateTime) ? dateTime : null;
}
