2024-07-04 11:02:45 +05:00
|
|
|
using System;
|
2023-03-06 16:30:36 +05:00
|
|
|
using System.Text.Json;
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
namespace AsbCloudWebApi.Converters;
|
2023-05-19 16:51:41 +05:00
|
|
|
|
2023-03-06 16:30:36 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
public class DateOnlyJsonConverter : JsonConverter<DateOnly>
|
|
|
|
{
|
|
|
|
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
|
|
{
|
|
|
|
return DateOnly.FromDateTime(reader.GetDateTime());
|
2023-03-06 16:30:36 +05:00
|
|
|
}
|
2023-05-19 16:51:41 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
|
|
|
|
{
|
|
|
|
var isoDate = value.ToString("O");
|
|
|
|
writer.WriteStringValue(isoDate);
|
|
|
|
}
|
2023-03-06 16:30:36 +05:00
|
|
|
}
|