Struct EpochSecondsConverter
- Namespace
- DynaSharp.Serialization
- Assembly
- DynaSharp.dll
Converts DateTimeOffset to and from a number value (N) of whole seconds since 1970-01-01T00:00:00Z, the form DynamoDB's
time to live (TTL) expects. Use it with [DynamoDbConverter] on the property that is the table's TTL attribute.
public readonly struct EpochSecondsConverter : IDynamoDbConverter<DateTimeOffset>
- Implements
- Inherited Members
Remarks
DynamoDB deletes an item some time after the instant in its TTL attribute, usually within days, and only if the attribute is a number. A string, which is what DateTimeOffsetConverter writes, is ignored. Seconds are counted in UTC, so the offset is not preserved.
Fractions of a second are dropped when writing (the value is rounded down). Reading accepts only whole numbers of seconds from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z, the range of DateTimeOffset; a number with a fraction, such as epoch milliseconds with a decimal point, is rejected rather than rounded.
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
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
- DateTimeOffset
The value.
Exceptions
- JsonException
typeis not Number.- OverflowException
The number is not a whole number of seconds in the range of DateTimeOffset. The message does not quote the number.
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
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.
valueDateTimeOffsetThe value.