Crunchy-Downloader/CRD/Utils/JsonConv/UtcToLocalTimeConverter.cs
Elwador 6aa10cb2c2 Add - Added a button to manually match Sonarr series
Add - Available dubs/subs overall to history series - not all dubs/subs are available for every season/episode
Fix - Subscription end date was in UTC, causing the program to not recognize an active premium subscription  https://github.com/Crunchy-DL/Crunchy-Downloader/issues/74
2024-08-15 02:27:49 +02:00

19 lines
No EOL
794 B
C#

using System;
using Newtonsoft.Json;
namespace CRD.Utils.JsonConv;
public class UtcToLocalTimeConverter : JsonConverter<DateTime>{
public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer){
return reader.Value switch{
null => DateTime.MinValue,
DateTime dateTime when dateTime.Kind == DateTimeKind.Utc => dateTime.ToLocalTime(),
DateTime dateTime => dateTime,
_ => throw new JsonSerializationException($"Unexpected token parsing date. Expected DateTime, got {reader.Value.GetType()}.")
};
}
public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer){
writer.WriteValue(value);
}
}