< Summary

Information
Class: MyNet.Primitives.Intervals.TimeRange
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Intervals/TimeRange.cs
Tag: 323_28699572109
Line coverage
54%
Covered lines: 6
Uncovered lines: 5
Coverable lines: 11
Total lines: 46
Line coverage: 54.5%
Branch coverage
28%
Covered branches: 4
Total branches: 14
Branch coverage: 28.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Duration()50%22100%
get_CrossesMidnight()100%11100%
Contains(...)75%44100%
Create(...)0%7280%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Intervals/TimeRange.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TimeRange.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8
 9namespace MyNet.Primitives.Intervals;
 10
 11/// <summary>
 12/// Represents a closed interval of time, defined by a start and an end time. The interval includes both the start and e
 13/// </summary>
 14/// <param name="start">The start time of the interval.</param>
 15/// <param name="end">The end time of the interval.</param>
 2116public sealed class TimeRange(TimeOnly start, TimeOnly end) : Interval<TimeOnly, TimeRange>(new IntervalBoundary<TimeOnl
 17{
 18    /// <summary>
 19    /// Gets the duration of the time range as a TimeSpan value, calculated as the difference between the end time and t
 20    /// </summary>
 21    public TimeSpan Duration =>
 1822        !CrossesMidnight
 1823            ? End!.Value.Value - Start!.Value.Value
 1824            : TimeSpan.FromDays(1) - Start!.Value.Value.ToTimeSpan() + End!.Value.Value.ToTimeSpan();
 25
 26    /// <summary>
 27    /// Gets a value indicating whether the time range crosses midnight. A time range is considered to cross midnight if
 28    /// </summary>
 3029    public bool CrossesMidnight => End!.Value.Value < Start!.Value.Value;
 30
 31    /// <summary>
 32    /// Determines whether a given TimeOnly value falls within the time range. If the time range does not cross midnight
 33    /// </summary>
 34    /// <param name="value">The TimeOnly value to check.</param>
 35    /// <returns><c>true</c> if the value falls within the time range; otherwise, <c>false</c>.</returns>
 36    public override bool Contains(TimeOnly value)
 937        => !CrossesMidnight ? base.Contains(value) : value >= Start!.Value.Value || value <= End!.Value.Value;
 38
 39    /// <inheritdoc />
 040    protected override TimeRange Create(IntervalBoundary<TimeOnly>? start, IntervalBoundary<TimeOnly>? end) => !start.Ha
 041        ? throw new InvalidOperationException("TimeRange must be bounded.")
 042        : !start.Value.IsInclusive || !end.Value.IsInclusive
 043            ? throw new InvalidOperationException("TimeRange only supports inclusive boundaries.")
 044            : new(start.Value.Value, end.Value.Value);
 45}
 46