1
0
mirror of synced 2024-11-28 00:20:53 +01:00
TaikoLocalServer/LocalSaveModScoreMigrator/DateTimeConverter.cs

22 lines
760 B
C#
Raw Normal View History

2023-09-09 14:58:20 +02:00
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));
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));
}
}