< Summary

Information
Class: System.Net.HttpDateParser
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\Common\src\System\Net\HttpDateParser.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 53
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
TryParse(...)50%22100%

File(s)

D:\runner\runtime\src\libraries\Common\src\System\Net\HttpDateParser.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.Globalization;
 5
 6namespace System.Net
 7{
 8    internal static class HttpDateParser
 9    {
 110        private static readonly string[] s_dateFormats = new string[] {
 111            // "r", // RFC 1123, required output format but too strict for input
 112            "ddd, d MMM yyyy H:m:s 'GMT'", // RFC 1123 (r, except it allows both 1 and 01 for date and time)
 113            "ddd, d MMM yyyy H:m:s 'UTC'", // RFC 1123, UTC
 114            "ddd, d MMM yyyy H:m:s", // RFC 1123, no zone - assume GMT
 115            "d MMM yyyy H:m:s 'GMT'", // RFC 1123, no day-of-week
 116            "d MMM yyyy H:m:s 'UTC'", // RFC 1123, UTC, no day-of-week
 117            "d MMM yyyy H:m:s", // RFC 1123, no day-of-week, no zone
 118            "ddd, d MMM yy H:m:s 'GMT'", // RFC 1123, short year
 119            "ddd, d MMM yy H:m:s 'UTC'", // RFC 1123, UTC, short year
 120            "ddd, d MMM yy H:m:s", // RFC 1123, short year, no zone
 121            "d MMM yy H:m:s 'GMT'", // RFC 1123, no day-of-week, short year
 122            "d MMM yy H:m:s 'UTC'", // RFC 1123, UTC, no day-of-week, short year
 123            "d MMM yy H:m:s", // RFC 1123, no day-of-week, short year, no zone
 124
 125            "dddd, d'-'MMM'-'yy H:m:s 'GMT'", // RFC 850
 126            "dddd, d'-'MMM'-'yy H:m:s 'UTC'", // RFC 850, UTC
 127            "dddd, d'-'MMM'-'yy H:m:s zzz", // RFC 850, offset
 128            "dddd, d'-'MMM'-'yy H:m:s", // RFC 850 no zone
 129            "ddd MMM d H:m:s yyyy", // ANSI C's asctime() format
 130
 131            "ddd, d MMM yyyy H:m:s zzz", // RFC 5322
 132            "ddd, d MMM yyyy H:m:s", // RFC 5322 no zone
 133            "d MMM yyyy H:m:s zzz", // RFC 5322 no day-of-week
 134            "d MMM yyyy H:m:s", // RFC 5322 no day-of-week, no zone
 135        };
 36
 37        internal static bool TryParse(ReadOnlySpan<char> input, out DateTimeOffset result)
 9638        {
 39            // None of the relevant patterns have whitespace at the beginning or end, so trim the input of
 40            // any whitespace.  We can then use strict "r" matching, or if we have to fall back to trying
 41            // lots of patterns, only allow inner whitespace rather than leading or trailing whitespace.
 9642            input = input.Trim();
 43
 44            // First try strict parsing for "r" with no options, as it's an order of magnitude faster than general parsi
 45            // any individual format in s_dateFormats, allocation-free, and also likely to succeed.  If it doesn't, then
 46            // fall back to trying each of the various date formats listed earlier, in order, to be accomodating and
 47            // accept a wide variety of old formats.
 9648            return
 9649                DateTimeOffset.TryParseExact(input, "r", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out resu
 9650                DateTimeOffset.TryParseExact(input, s_dateFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.Allo
 9651        }
 52    }
 53}