< Summary

Information
Class: System.Net.Http.Headers.TimeSpanHeaderParser
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\TimeSpanHeaderParser.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
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%11100%
GetParsedValueLength(...)100%66100%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\TimeSpanHeaderParser.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.Globalization;
 6
 7namespace System.Net.Http.Headers
 8{
 9    internal sealed class TimeSpanHeaderParser : BaseHeaderParser
 10    {
 111        internal static readonly TimeSpanHeaderParser Parser = new TimeSpanHeaderParser();
 12
 13        private TimeSpanHeaderParser()
 114            : base(false)
 115        {
 116        }
 17
 18        public override string ToString(object value)
 1219        {
 1220            Debug.Assert(value is TimeSpan);
 21
 1222            return ((int)((TimeSpan)value).TotalSeconds).ToString(NumberFormatInfo.InvariantInfo);
 1223        }
 24
 25        protected override int GetParsedValueLength(string value, int startIndex, object? storeValue,
 26            out object? parsedValue)
 1627        {
 1628            parsedValue = null;
 29
 1630            int numberLength = HttpRuleParser.GetNumberLength(value, startIndex, false);
 31
 1632            if ((numberLength == 0) || (numberLength > HttpRuleParser.MaxInt32Digits))
 233            {
 234                return 0;
 35            }
 36
 37            int result;
 1438            if (!HeaderUtilities.TryParseInt32(value, startIndex, numberLength, out result))
 239            {
 240                return 0;
 41            }
 42
 1243            parsedValue = new TimeSpan(0, 0, result);
 1244            return numberLength;
 1645        }
 46    }
 47}