Fixes parsing for datetime in CardPrice JsonConverter

This commit is contained in:
Serraniel 2023-03-03 15:40:25 +01:00
parent 719b8f0128
commit 0886230dda
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
@ -81,8 +82,9 @@ internal class CardPriceConverter : JsonConverter<IEnumerable<CardPrice>>
value = reader.GetString();
else if (propertyType == typeof(decimal))
value = reader.GetDecimal();
else if (propertyType == typeof(DateTime))
if (DateTime.TryParse(reader.GetString(), out var dt))
else if (propertyType == typeof(DateTime?))
if (DateTime.TryParseExact(reader.GetString(), "MM/dd/yyyy",
CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt))
value = dt;
property.SetValue(cardPrice, value);