diff --git a/src/api/SIGCM2.Api/Json/DateOnlyJsonConverter.cs b/src/api/SIGCM2.Api/Json/DateOnlyJsonConverter.cs new file mode 100644 index 0000000..ca1b1e1 --- /dev/null +++ b/src/api/SIGCM2.Api/Json/DateOnlyJsonConverter.cs @@ -0,0 +1,31 @@ +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace SIGCM2.Api.Json; + +/// +/// JSON converter for that uses the "yyyy-MM-dd" ISO format. +/// +/// UDT-011: Ensures Cat2 date fields (VigenciaDesde, etc.) never serialize as +/// "2026-05-01T00:00:00" or with a UTC suffix "Z", which would mislead consumers +/// into treating civil Argentine dates as absolute UTC instants. +/// +public sealed class DateOnlyJsonConverter : JsonConverter +{ + private const string DateFormat = "yyyy-MM-dd"; + + public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var str = reader.GetString(); + if (str is null) + throw new JsonException("DateOnly value cannot be null."); + + return DateOnly.ParseExact(str, DateFormat, CultureInfo.InvariantCulture); + } + + public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToString(DateFormat, CultureInfo.InvariantCulture)); + } +}