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;
|
2019-05-02 20:53:45 +02:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Utilities
|
|
|
|
|
{
|
|
|
|
|
public class DateTimeConverter : IValueConverter
|
|
|
|
|
{
|
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();
|
2021-10-28 18:52:41 +02:00
|
|
|
|
return string.Format("{0} {1}",
|
|
|
|
|
_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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|