|
|
|
|
namespace Connected;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A ready made DateTime? to string binding converter with configurable date format and culture
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class NullableDateConverter : ToStringConverter<DateTime?>
|
|
|
|
|
{
|
|
|
|
|
public string DateFormat { get; set; }
|
|
|
|
|
|
|
|
|
|
public NullableDateConverter(string format = "yyyy-MM-dd") => DateFormat = format;
|
|
|
|
|
|
|
|
|
|
protected override string? ConvertValue(DateTime? value) => value?.ToString(DateFormat, Culture);
|
|
|
|
|
|
|
|
|
|
protected override DateTime? ConvertValueBack(string? value) => DateTime.ParseExact(value, DateFormat, Culture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A ready made DateTime to string binding converter with configurable date format and culture
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DateConverter : ToStringConverter<DateTime>
|
|
|
|
|
{
|
|
|
|
|
public string DateFormat { get; set; }
|
|
|
|
|
|
|
|
|
|
public DateConverter(string format = "yyyy-MM-dd") => DateFormat = format;
|
|
|
|
|
|
|
|
|
|
protected override string? ConvertValue(DateTime value) => value.ToString(DateFormat, Culture);
|
|
|
|
|
|
|
|
|
|
protected override DateTime ConvertValueBack(string? value) => DateTime.ParseExact(value, DateFormat, Culture);
|
|
|
|
|
}
|