< Summary

Class:Azure.Search.Documents.SearchDateTimeOffsetConverter
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Serialization\SearchDateTimeOffsetConverter.cs
Covered lines:7
Uncovered lines:0
Coverable lines:7
Total lines:43
Line coverage:100% (7 of 7)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Shared()-100%100%
.cctor()-100%100%
Read(...)-100%100%
Write(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Serialization\SearchDateTimeOffsetConverter.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Diagnostics;
 6using System.Globalization;
 7using System.Text.Json;
 8using System.Text.Json.Serialization;
 9using Azure.Core;
 10
 11namespace Azure.Search.Documents
 12{
 13    /// <summary>
 14    /// Convert dates to and from JSON.  They're expected to be in 8601 UTC.
 15    /// </summary>
 16    internal class SearchDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
 17    {
 118        public static SearchDateTimeOffsetConverter Shared { get; } =
 119            new SearchDateTimeOffsetConverter();
 20
 21        public override DateTimeOffset Read(
 22            ref Utf8JsonReader reader,
 23            Type typeToConvert,
 24            JsonSerializerOptions options)
 25        {
 26            Debug.Assert(typeToConvert != null);
 27            Debug.Assert(options != null);
 28
 13629            string text = reader.GetString();
 13630            return DateTimeOffset.Parse(text, CultureInfo.InvariantCulture);
 31        }
 32
 33        public override void Write(
 34            Utf8JsonWriter writer,
 35            DateTimeOffset value,
 36            JsonSerializerOptions options)
 37        {
 2838            Argument.AssertNotNull(writer, nameof(writer));
 39            Debug.Assert(options != null);
 2840            writer.WriteStringValue(JsonSerialization.Date(value, CultureInfo.InvariantCulture));
 2841        }
 42    }
 43}