FSharp.Azure.Cosmos 1.2.0

Edit this page

TimeSpanTicksConverter Type

Writes a TimeSpan as a JSON number, its number of ticks, and reads the same number.

The converter of System.Text.Json writes a TimeSpan as text, for example "2.00:00:00". Cosmos DB compares text by character code. Thus "2.00:00:00" sorts after "10.00:00:00". A number sorts and compares in time order. Use this converter for each TimeSpan that a query compares or sorts.

One tick is 100 nanoseconds. Cosmos DB defines a JSON number as a 64-bit floating-point number. Such a number holds each whole number up to 2^53 exactly, which is about 28 years of ticks. A longer TimeSpan can lose digits in a client that reads the number as a floating-point number.

The converter also reads the text that System.Text.Json writes, so a container that holds old documents stays readable. An old document keeps its text, and the text does not sort in time order, until you write the document again.

To use the converter, add it to Converters. Then set the options in UseSystemTextJsonSerializerWithOptions. The converter also handles Nullable{T} values and the keys of a dictionary.

Constructors

Constructor Description

TimeSpanTicksConverter()

Full Usage: TimeSpanTicksConverter()

Returns: TimeSpanTicksConverter
Returns: TimeSpanTicksConverter