Table of Contents

Struct SdkDateTimeConverter

Namespace
DynaSharp.Serialization
Assembly
DynaSharp.dll

Converts DateTime to and from a string value (S) in the form DynamoDBContext of the AWS SDK for .NET stores: the instant in UTC with three fraction digits, 2026-10-31T12:00:00.123Z. It is opt-in, with [DynamoDbConverter] on the property or [assembly: DynamoDbDefaultConverter(typeof(DateTime), typeof(SdkDateTimeConverter))], for a table the SDK wrote, where DateTimeConverter would write seven digits, 2026-10-31T12:00:00.1230000Z, which an equality condition and a key built from an old value no longer match.

public readonly struct SdkDateTimeConverter : IDynamoDbConverter<DateTime>
Implements
Inherited Members

Remarks

The kinds go as in the SDK, version 4, in the conversions V1 and V2 alike. Utc is written as it is, and Local is converted to UTC. Unspecified is taken for local time and converted too, so what it stores depends on the time zone of the machine, where DateTimeConverter rejects it. Ticks below the millisecond are cut off, not rounded: 12:00:00.1239999 is stored as 12:00:00.123Z.

A value read is always Utc, which is what the SDK gives under its default RetrieveDateTimeInUtc = true. Code that ran with RetrieveDateTimeInUtc = false, or on version 3 of the SDK, got Local and calls ToLocalTime() on what this reads.

Reading accepts what DateTimeConverter accepts: zero to seven fraction digits and Z or an offset, so a property can move from one converter to the other and read both. Text without Z or an offset is rejected, although the SDK reads it as UTC: the SDK never writes it. The width is fixed, so the stored text orders chronologically, and a plain sort key has the ranges.

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

reader DynamoDbReader

The 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.

type AttributeType

The 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

type is not String.

FormatException

The text is not an ISO 8601 date and time with Z or 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

writer DynamoDbWriter

The 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.

value DateTime

The value.