Class DateTimeOffsetSerializer
Type serializer for DateTimeOffset values. Converts each value to and from
the ISO 8601 round-trip format string ("o"), which preserves both the date-time
instant and the UTC offset, for example 2024-06-15T10:30:00.0000000+02:00.
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public sealed class DateTimeOffsetSerializer : TypeSerializerBase<DateTimeOffset>, ITypeSerializer<DateTimeOffset>, ITypeSerializer
Remarks
Unlike DateTimeSerializer, DateTimeOffsetSerializer always
retains the original UTC offset, making it the preferred choice when timezone context
must survive a round-trip (e.g., user-facing timestamps, log entries).
On read, RoundtripKind is passed to Parse(string, IFormatProvider, DateTimeStyles) so the offset information is preserved exactly as written.
Use the shared Instance singleton rather than creating new instances;
DateTimeOffsetSerializer carries no mutable state and is safe to share across
threads.
Fields
Instance
Shared, reusable singleton instance of DateTimeOffsetSerializer.
Prefer this over allocating a new instance wherever a DateTimeOffsetSerializer is needed.
Declaration
public static readonly DateTimeOffsetSerializer Instance
Field Value
| Type | Description |
|---|---|
| DateTimeOffsetSerializer |
Methods
Read(IScyllaReader, ISerializationContext)
Reads an ISO 8601 string from the reader and parses it back to a DateTimeOffset.
Declaration
public override DateTimeOffset Read(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The reader positioned at a string token. Never |
| ISerializationContext | context | The active serialization context. Never |
Returns
| Type | Description |
|---|---|
| DateTimeOffset | The deserialized DateTimeOffset value with its original UTC offset preserved. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| FormatException | Thrown by Parse(string, IFormatProvider, DateTimeStyles) if the string is not a valid ISO 8601 date-time-with-offset representation. |
Write(DateTimeOffset, IScyllaWriter, ISerializationContext)
Converts value to an ISO 8601 round-trip string including UTC offset
and writes it to the output via WriteString(string).
Declaration
public override void Write(DateTimeOffset value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | value | The DateTimeOffset to serialize. Both the instant and the UTC offset are preserved in the emitted string. |
| IScyllaWriter | writer | The writer that receives the serialized token. Never |
| ISerializationContext | context | The active serialization context. Never |