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 formatted year string. /// public class DateTimeToYearTextConverter : IValueConverter { /// /// Converts a to a formatted year string. /// /// The to convert. /// A formatted year string of the . [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Convert(DateTime value) => value.ToString("yyyy"); /// [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Convert(DateTime? value) => Convert(value.HasValue ? value.Value : DateTime.MinValue); /// public object Convert(object value, Type targetType, object parameter, string language) { return Convert(value as DateTime?); } /// public object ConvertBack(object value, Type targetType, object parameter, string language) { throw new NotImplementedException(); } } }