Skip to content

Commit 0841259

Browse files
author
Stéphane ANDRE (E104915)
committed
Enhance TimeConverter to handle DateTime values
1 parent ac34bec commit 0841259

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/MyNet.Wpf/Converters/TimeConverter.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Globalization;
66
using System.Windows.Data;
7-
using Microsoft.VisualBasic;
87
using MyNet.Utilities;
98
using MyNet.Utilities.Localization;
109

@@ -29,7 +28,10 @@ public class TimeConverter : IValueConverter
2928

3029
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
3130
{
32-
var time = value is TimeOnly timeOnly ? timeOnly : (TimeOnly?)(value is TimeSpan ts && ts != TimeSpan.MinValue ? TimeOnly.FromTimeSpan(ts) : null);
31+
var time = value is TimeOnly timeOnly ? timeOnly
32+
: value is TimeSpan ts && ts != TimeSpan.MinValue ? TimeOnly.FromTimeSpan(ts)
33+
: value is DateTime dt && dt != DateTime.MinValue ? dt.ToTime()
34+
: (TimeOnly?)null;
3335

3436
if (!time.HasValue) return null;
3537

0 commit comments

Comments
 (0)