DateConverter.cs 918 B

12345678910111213141516171819202122232425262728293031
  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 TeacheresAndCourses.Converter
  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)
  15. {
  16. return new DateTimeOffset((DateTime)value, TimeSpan.Zero);
  17. }
  18. return null;
  19. }
  20. public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  21. {
  22. if (value is DateTimeOffset myDateTimeOffset)
  23. {
  24. return new DateTime(myDateTimeOffset.Year, myDateTimeOffset.Month, myDateTimeOffset.Day);
  25. }
  26. return null;
  27. }
  28. }
  29. }