Class UtcDateTimeConverter
- Namespace
- FishMMO.ControlPanel.Services
- Assembly
- FishMMO-ControlPanel.dll
Serializes every DateTime with an explicit UTC designator.
public sealed class UtcDateTimeConverter : JsonConverter<DateTime>
- Inheritance
-
UtcDateTimeConverter
- Inherited Members
Remarks
Every timestamp column in this schema is timestamp without time zone holding a UTC
value — the columns are even named for it, occurred_utc, last_saved,
time_deleted. EF reads them back as Unspecified, and
System.Text.Json then writes an unspecified kind with no designator at all:
"2026-09-11T02:10:00".
A browser parses that as local time. Not as UTC, and not as an error — every date in the panel was silently shifted by the operator's offset, which on this developer's machine is seven hours. The failure is invisible precisely where it matters: a character "last saved 7 hours ago" that was in fact saved a minute ago reads as a stale row, and an audit entry appears to have happened in the future.
Stamping UTC on the way out is a statement of fact rather than a guess: the value in the column is UTC. Reading accepts either form, so a client that does send a designator is not broken by this.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type DateTime.
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- DateTime
The converted value.
Write(Utf8JsonWriter, DateTime, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueDateTimeThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.