123456789101112131415161718192021222324252627282930313233 |
- using System;
- using System.Globalization;
- using InABox.Core;
- namespace InABox.WPF;
- public class DateToStringConverter : UtilityConverter<DateTime,String>
- {
- public string Format { get; }
-
- public DateToStringConverter(string? format = null)
- {
- Format = format ?? "dd/MM/yyyy";
- }
-
- public override string Convert(DateTime value)
- {
- if (value is DateTime datetime && !datetime.IsEmpty())
- return String.Format("{0:" + Format + "}", datetime);
- return "";
- }
- public override DateTime Deconvert(string value)
- {
- if (String.IsNullOrWhiteSpace(value))
- return DateTime.MinValue;
-
- if (DateTime.TryParseExact(value, Format, CultureInfo.InvariantCulture, DateTimeStyles.None,
- out DateTime result))
- return result;
- return DateTime.MinValue;
- }
- }
|