mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
add proper converter for legacy datetime
This commit is contained in:
parent
4b87bbf53d
commit
b0532c549a
37
Jellyfin.Api/TypeConverters/DateTimeTypeConverter.cs
Normal file
37
Jellyfin.Api/TypeConverters/DateTimeTypeConverter.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
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)
|
||||||
|
{
|
||||||
|
if (DateTime.TryParseExact(dateString, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var dateTime))
|
||||||
|
{
|
||||||
|
return dateTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.ConvertFrom(context, culture, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
using System.Net.Http;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Jellyfin.Api.TypeConverters;
|
||||||
using Jellyfin.Server.Extensions;
|
using Jellyfin.Server.Extensions;
|
||||||
using Jellyfin.Server.Middleware;
|
using Jellyfin.Server.Middleware;
|
||||||
using Jellyfin.Server.Models;
|
using Jellyfin.Server.Models;
|
||||||
@ -94,6 +96,9 @@ namespace Jellyfin.Server
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.Use(serverApplicationHost.ExecuteHttpHandlerAsync);
|
app.Use(serverApplicationHost.ExecuteHttpHandlerAsync);
|
||||||
|
|
||||||
|
// Add type descriptor for legacy datetime parsing.
|
||||||
|
TypeDescriptor.AddAttributes(typeof(DateTime?), new TypeConverterAttribute(typeof(DateTimeTypeConverter)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user