2019-05-02 20:53:45 +02:00
|
|
|
|
using System;
|
2021-10-28 18:52:41 +02:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.Core.Utilities;
|
2023-09-29 16:02:19 +02:00
|
|
|
|
using Microsoft.Maui.Controls;
|
|
|
|
|
using Microsoft.Maui;
|
2019-05-02 20:53:45 +02:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Utilities
|
|
|
|
|
{
|
|
|
|
|
public class DateTimeConverter : IValueConverter
|
|
|
|
|
{
|
2023-10-19 22:46:26 +02:00
|
|
|
|
public string Format { get; set; } = "{0} {1}";
|
|
|
|
|
|
2021-10-28 18:52:41 +02:00
|
|
|
|
private readonly ILocalizeService _localizeService;
|
|
|
|
|
|
|
|
|
|
public DateTimeConverter()
|
|
|
|
|
{
|
|
|
|
|
_localizeService = ServiceContainer.Resolve<ILocalizeService>("localizeService");
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 20:53:45 +02:00
|
|
|
|
public object Convert(object value, Type targetType, object parameter,
|
|
|
|
|
System.Globalization.CultureInfo culture)
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (targetType != typeof(string))
|
2019-05-02 20:53:45 +02:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("The target must be a string.");
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (value == null)
|
2019-05-02 20:53:45 +02:00
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
2019-05-14 15:01:07 +02:00
|
|
|
|
var d = ((DateTime)value).ToLocalTime();
|
2023-10-19 22:46:26 +02:00
|
|
|
|
return string.Format(Format,
|
2021-10-28 18:52:41 +02:00
|
|
|
|
_localizeService.GetLocaleShortDate(d),
|
|
|
|
|
_localizeService.GetLocaleShortTime(d));
|
2019-05-02 20:53:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter,
|
|
|
|
|
System.Globalization.CultureInfo culture)
|
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|