1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-26 10:36:21 +02:00
bitwarden-mobile/src/Core/Utilities/DateTimeConverter.cs
Dinis Vieira e840dc2e30
Merge branch 'master' into feature/maui-migration
Fixed conflicts and added null check on ForwardEmailDomainName

# Conflicts:
#	src/Core/Pages/Vault/CipherAddEditPage.xaml
#	src/Core/Pages/Vault/CipherDetailsPage.xaml
#	src/iOS.Core/Renderers/CollectionView/ExtendedGroupableItemsViewController.cs
2023-11-05 23:59:30 +00:00

44 lines
1.3 KiB
C#

using System;
using Bit.App.Abstractions;
using Bit.Core.Utilities;
using Microsoft.Maui.Controls;
using Microsoft.Maui;
namespace Bit.App.Utilities
{
public class DateTimeConverter : IValueConverter
{
public string Format { get; set; } = "{0} {1}";
private readonly ILocalizeService _localizeService;
public DateTimeConverter()
{
_localizeService = ServiceContainer.Resolve<ILocalizeService>("localizeService");
}
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (targetType != typeof(string))
{
throw new InvalidOperationException("The target must be a string.");
}
if (value == null)
{
return string.Empty;
}
var d = ((DateTime)value).ToLocalTime();
return string.Format(Format,
_localizeService.GetLocaleShortDate(d),
_localizeService.GetLocaleShortTime(d));
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
}