TimeToStringConverter.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 ShakerApp.Convert
  9. {
  10. internal class TimeToStringConverter : IValueConverter
  11. {
  12. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  13. {
  14. if(value is float time)
  15. {
  16. return $"{(uint)time / 3600:D2}:{((uint)time % 3600) / 60:D2}:{(uint)time % 60:D2}";
  17. }
  18. else if (value is double dtime)
  19. {
  20. return $"{(uint)dtime / 3600:D2}:{((uint)dtime % 3600) / 60:D2}:{(uint)dtime % 60:D2}";
  21. }
  22. else if (value is uint utime)
  23. {
  24. return $"{(uint)utime / 3600:D2}:{((uint)utime % 3600) / 60:D2}:{(uint)utime % 60:D2}";
  25. }
  26. else if (value is int itime)
  27. {
  28. return $"{(uint)itime / 3600:D2}:{((uint)itime % 3600) / 60:D2}:{(uint)itime % 60:D2}";
  29. }
  30. else
  31. {
  32. return "00:00:00";
  33. }
  34. }
  35. public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  36. {
  37. throw new NotImplementedException();
  38. }
  39. }
  40. }