using System.Globalization; using System.Text.Json; using System.Text.Json.Serialization; namespace OnlineMetodist.API.Services { //public class JsonDateOnlyConverter : JsonConverter //{ // // Define the date format the data is in // private const string DateFormat = "yyyy-MM-dd"; // // This is the deserializer // public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) // { // return DateOnly.ParseExact(reader.GetString()!, // DateFormat); // } // // This is the serializer // public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options) // { // writer.WriteStringValue(value.ToString( // DateFormat, CultureInfo.InvariantCulture)); // } //} public class DateOnlyJsonConverter : JsonConverter { private const string Format = "yyyy-MM-dd"; public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return DateOnly.ParseExact(reader.GetString()!, Format, CultureInfo.InvariantCulture); } public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options) { writer.WriteStringValue(value.ToString(Format, CultureInfo.InvariantCulture)); } } }