2020-08-10 13:58:06 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.TypeConverters
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Custom datetime parser.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DateTimeTypeConverter : TypeConverter
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
|
|
|
|
{
|
|
|
|
|
if (sourceType == typeof(string))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.CanConvertFrom(context, sourceType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
|
|
|
|
{
|
|
|
|
|
if (value is string dateString)
|
|
|
|
|
{
|
2020-08-12 14:43:57 -04:00
|
|
|
|
// Mark Played Item.
|
2020-08-12 15:07:11 -04:00
|
|
|
|
if (DateTime.TryParseExact(dateString, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var dateTime))
|
2020-08-10 13:58:06 -04:00
|
|
|
|
{
|
2020-08-12 15:07:11 -04:00
|
|
|
|
return dateTime;
|
2020-08-12 14:43:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get Activity Logs.
|
2020-08-12 15:07:11 -04:00
|
|
|
|
if (DateTime.TryParse(dateString, null, DateTimeStyles.RoundtripKind, out dateTime))
|
2020-08-12 14:43:57 -04:00
|
|
|
|
{
|
2020-08-12 15:07:11 -04:00
|
|
|
|
return dateTime;
|
2020-08-10 13:58:06 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.ConvertFrom(context, culture, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|