Table of Contents

Struct OffsetTimestampConverter

Namespace
DynaSharp.Serialization
Assembly
DynaSharp.dll

Converts DateTimeOffset to and from a string value (S) that keeps the offset, in the round-trip form 2026-11-20T11:00:00.0000000+01:00: always seven fraction digits, always an offset, +00:00 for UTC. It is opt-in, with [DynamoDbConverter] on the property or [assembly: DynamoDbDefaultConverter(typeof(DateTimeOffset), typeof(OffsetTimestampConverter))], since DateTimeOffsetConverter stores the instant in UTC.

public readonly struct OffsetTimestampConverter : IDynamoDbConverter<DateTimeOffset>
Implements
Inherited Members

Remarks

The text does not order chronologically across offsets. 2026-11-20T11:00:00.0000000+01:00 is 10:00 in UTC and sorts after 2026-11-20T10:30:00.0000000+00:00, which is later. A key condition, a BETWEEN or a sort over the attribute is right only among values of one offset, and an equality condition finds the text, so the same instant at another offset does not match. Use DateTimeOffsetConverter for an attribute that is compared, and keep the offset beside it if it matters.

A value read has the offset of its text. Reading accepts what DateTimeOffsetConverter accepts: zero to seven fraction digits and an offset or Z, which reads with offset zero, so values that converter wrote read too. Text without Z or an offset is rejected, since it would name a local time without saying whose.

Explicit Interface Implementations

Read(ref DynamoDbReader, AttributeType)

Reads the attribute value the reader is positioned on.

static DateTimeOffset 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

DateTimeOffset

The value.

Exceptions

JsonException

type is not String.

FormatException

The text is not an ISO 8601 date and time with Z or an offset, or outside the range of DateTimeOffset. The message does not quote the text.

Write(DynamoDbWriter, DateTimeOffset)

Writes a value as one complete attribute value, for example with WriteNumber<T>(T).

static void Write(DynamoDbWriter writer, DateTimeOffset 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 DateTimeOffset

The value.