< Summary

Information
Class: System.Net.Http.Headers.DateHeaderParser
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\DateHeaderParser.cs
Line coverage
60%
Covered lines: 15
Uncovered lines: 10
Coverable lines: 25
Total lines: 54
Line coverage: 60%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor()100%11100%
ToString(...)100%110%
TryParseValue(...)75%8864.7%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\DateHeaderParser.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace System.Net.Http.Headers
 8{
 9    // Don't derive from BaseHeaderParser since parsing is delegated to DateTimeOffset.TryParseExact()
 10    // which will remove leading, trailing, and whitespace in the middle of the string.
 11    internal sealed class DateHeaderParser : HttpHeaderParser
 12    {
 113        internal static readonly DateHeaderParser Parser = new DateHeaderParser();
 14
 15        private DateHeaderParser()
 116            : base(false)
 117        {
 118        }
 19
 20        public override string ToString(object value)
 021        {
 022            Debug.Assert(value is DateTimeOffset);
 23
 024            return ((DateTimeOffset)value).ToString("r");
 025        }
 26
 27        public override bool TryParseValue([NotNullWhen(true)] string? value, object? storeValue, ref int index, [NotNul
 4228        {
 4229            parsedValue = null;
 30
 31            // Some headers support empty/null values. This one doesn't.
 4232            if (string.IsNullOrEmpty(value) || (index == value.Length))
 2633            {
 2634                return false;
 35            }
 36
 1637            ReadOnlySpan<char> dateString = value;
 1638            if (index > 0)
 039            {
 040                dateString = value.AsSpan(index);
 041            }
 42
 43            DateTimeOffset date;
 1644            if (!HttpDateParser.TryParse(dateString, out date))
 1645            {
 1646                return false;
 47            }
 48
 049            index = value.Length;
 050            parsedValue = date;
 051            return true;
 4252        }
 53    }
 54}