27 lines
763 B
C#
27 lines
763 B
C#
using System;
|
|
using System.Globalization;
|
|
using Avalonia.Data.Converters;
|
|
|
|
namespace AutoCat.Extensions;
|
|
|
|
public class DateConverter: IValueConverter
|
|
{
|
|
private static readonly DateTime Epoch = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is not double timestamp)
|
|
return null;
|
|
|
|
if (timestamp == 0)
|
|
return null;
|
|
|
|
var dateTime = Epoch.AddMilliseconds(timestamp).ToLocalTime();
|
|
return dateTime.ToString("g");
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |