Struct DateTimeConverter
- Namespace
- DynaSharp.Serialization
- Assembly
- DynaSharp.dll
Converts DateTime to and from a string value (S) holding the instant in UTC in the round-trip form
2026-10-31T12:00:00.0000000Z, the form DateTimeOffsetConverter writes, so both kinds of properties compare in one order.
public readonly struct DateTimeConverter : IDynamoDbConverter<DateTime>
- Implements
- Inherited Members
Remarks
A Utc value is written as it is and a Local value is converted to UTC.
Unspecified, which default(DateTime) has, is rejected because it names no instant, the same rule as in keys; the write of an entity says which property held it,
and SdkDateTimeConverter takes it for local time instead. A value read is always
Utc, so a Local value comes back as the same instant in UTC, not as equal.
Reading accepts the same forms as DateTimeOffsetConverter.
Explicit Interface Implementations
Read(ref DynamoDbReader, AttributeType)
Reads the attribute value the reader is positioned on.
static DateTime Read(ref DynamoDbReader reader, AttributeType type)
Parameters
readerDynamoDbReaderThe reader, positioned on the value after ReadStartAttribute() or TryReadStartAttribute(out AttributeType). The caller reads the closing brace afterwards, so the converter must read the value completely (all elements of a list, map or set) and nothing more.
typeAttributeTypeThe DynamoDB type of the value. Check it with Expect(AttributeType, AttributeType), which throws JsonException for types the converter does not support. Null is passed to the converter too, so it can map it to null where that makes sense.
Returns
- DateTime
The value.
Exceptions
- JsonException
typeis not String.- FormatException
The text is not an ISO 8601 date and time with
Zor an offset. The message does not quote the text.
Write(DynamoDbWriter, DateTime)
Writes a value as one complete attribute value, for example with WriteNumber<T>(T).
static void Write(DynamoDbWriter writer, DateTime value)
Parameters
writerDynamoDbWriterThe writer, positioned where a value is expected (after an attribute name, or inside a list). It is a ref struct, so it is never null and needs no check.
valueDateTimeThe value.
Exceptions
- ArgumentException
The kind of
valueis Unspecified.