DateConverter.cs 772 B

12345678910111213141516171819202122232425
  1. using Avalonia.Data.Converters;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Teachers.Converters
  9. {
  10. internal class DateConverter : IValueConverter
  11. {
  12. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  13. {
  14. if (value is DateTime) return new DateTimeOffset((DateTime)value, TimeSpan.Zero);
  15. return null;
  16. }
  17. public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  18. {
  19. if (value is DateTimeOffset date) return new DateTime(date.Year, date.Month, date.Day);
  20. return null;
  21. }
  22. }
  23. }