1
0
mirror of synced 2024-11-24 06:50:15 +01:00
TaikoLocalServer/LocalSaveModScoreMigrator/DateTimeConverter.cs

22 lines
760 B
C#
Raw Normal View History

using System.Diagnostics;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace LocalSaveModScoreMigrator;
public class DateTimeConverter : JsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Debug.Assert(typeToConvert == typeof(DateTime));
2022-10-26 18:42:41 +02:00
var dateTime = DateTime.ParseExact(reader.GetString() ?? string.Empty, "dd_MM_yy-HH_mm_ss",
CultureInfo.InvariantCulture);
return dateTime;
}
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture));
}
}