using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using Windows.UI.Xaml.Data;
namespace OwlCore.WinUI.Converters.Time
{
///
/// A converter that converts a given to a natural time format string.
///
public sealed class TimeSpanToTextConverter : IValueConverter
{
///
/// Converts a to a formatted string.
///
/// The to convert.
/// A formatted string of the .
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Convert(TimeSpan value)
{
if (value.Hours > 0)
return value.ToString(@"h\:mm\:ss");
else
return value.ToString(@"m\:ss");
}
///
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is TimeSpan timeSpan)
{
return Convert(timeSpan);
}
return Convert(TimeSpan.Zero);
}
///
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}