< Summary

Information
Class: Orchestrator.Commands.Observability.EvaluationTimeParser
Assembly: Orchestrator
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Observability/EvaluationTimeParser.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 51
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
ParseOrNull(...)100%22100%
Parse(...)100%11100%
Normalize(...)100%66100%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Observability/EvaluationTimeParser.cs

#LineLine coverage
 1using NodaTime;
 2using NodaTime.Text;
 3
 4namespace Orchestrator.Commands.Observability;
 5
 6internal static class EvaluationTimeParser
 7{
 18    private static readonly ZonedDateTimePattern EvaluationTimePattern =
 19        ZonedDateTimePattern.GeneralFormatOnlyIso.WithZoneProvider(DateTimeZoneProviders.Tzdb);
 10
 11    private const string ExampleValue = "2026-03-15T12:00:00 Europe/Berlin (+01)";
 12
 13    public static DateTimeOffset? ParseOrNull(string? value)
 14    {
 115        if (string.IsNullOrWhiteSpace(value))
 16        {
 117            return null;
 18        }
 19
 120        return Parse(value);
 21    }
 22
 23    public static DateTimeOffset Parse(string value)
 24    {
 125        ArgumentException.ThrowIfNullOrWhiteSpace(value);
 26
 127        value = Normalize(value);
 28
 29        try
 30        {
 131            return EvaluationTimePattern.Parse(value).GetValueOrThrow().ToDateTimeOffset();
 32        }
 133        catch (UnparsableValueException ex)
 34        {
 135            throw new ArgumentException(
 136                $"Evaluation time must use NodaTime's invariant ZonedDateTime 'G' pattern, for example '{ExampleValue}'.
 137                ex);
 38        }
 139    }
 40
 41    private static string Normalize(string value)
 42    {
 143        value = value.Trim();
 144        if (value.Length >= 2 && value[0] == '"' && value[^1] == '"')
 45        {
 146            value = value[1..^1];
 47        }
 48
 149        return value;
 50    }
 51}