Class DateTimeSerializer
Type serializer for DateTime values. Converts each value to and from the
ISO 8601 round-trip format string ("o"), which preserves the DateTimeKind
(Local, Utc, or Unspecified) and full sub-second precision.
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public sealed class DateTimeSerializer : TypeSerializerBase<DateTime>, ITypeSerializer<DateTime>, ITypeSerializer
Remarks
The "o" format specifier produces output such as
2024-06-15T10:30:00.0000000Z for UTC or
2024-06-15T10:30:00.0000000+02:00 for a local kind. On read,
RoundtripKind is passed to
Parse(string, IFormatProvider, DateTimeStyles) so that the
original DateTimeKind is faithfully restored.
Use the shared Instance singleton rather than creating new instances;
DateTimeSerializer carries no mutable state and is safe to share across threads.
Fields
Instance
Shared, reusable singleton instance of DateTimeSerializer.
Prefer this over allocating a new instance wherever a DateTimeSerializer is needed.
Declaration
public static readonly DateTimeSerializer Instance
Field Value
| Type | Description |
|---|---|
| DateTimeSerializer |
Methods
Read(IScyllaReader, ISerializationContext)
Reads an ISO 8601 string from the reader and parses it back to a DateTime.
Declaration
public override DateTime 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 |
|---|---|
| DateTime | The deserialized DateTime value with its original DateTimeKind preserved. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| FormatException | Thrown by Parse(string, IFormatProvider, DateTimeStyles) if the string is not a valid ISO 8601 date-time representation. |
Write(DateTime, IScyllaWriter, ISerializationContext)
Converts value to an ISO 8601 round-trip string and writes it to the
output via WriteString(string).
Declaration
public override void Write(DateTime value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | value | The DateTime value to serialize. The DateTimeKind is preserved in the emitted string. |
| IScyllaWriter | writer | The writer that receives the serialized token. Never |
| ISerializationContext | context | The active serialization context. Never |