< Summary

Information
Class: MyNet.Temporal.Intervals.TimeRange
Assembly: MyNet.Temporal
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/Intervals/TimeRange.cs
Tag: 342_31701152804
Line coverage
54%
Covered lines: 6
Uncovered lines: 5
Coverable lines: 11
Total lines: 51
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/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/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
 9using MyNet.Primitives.Intervals;
 10
 11namespace MyNet.Temporal.Intervals;
 12
 13/// <summary>
 14/// Represents a closed interval of time, defined by a start and an end time. The interval includes both the start and e
 15/// </summary>
 16/// <param name="start">The start time of the interval.</param>
 17/// <param name="end">The end time of the interval.</param>
 2118public sealed class TimeRange(TimeOnly start, TimeOnly end) : Interval<TimeOnly, TimeRange>(new IntervalBoundary<TimeOnl
 19{
 20    /// <summary>
 21    /// Gets the duration of the time range as a TimeSpan value, calculated as the difference between the end time and t
 22    /// </summary>
 23    public TimeSpan Duration =>
 1824        !CrossesMidnight
 1825            ? End!.Value.Value - Start!.Value.Value
 1826            : TimeSpan.FromDays(1) - Start!.Value.Value.ToTimeSpan() + End!.Value.Value.ToTimeSpan();
 27
 28    /// <summary>
 29    /// Gets a value indicating whether the time range crosses midnight. A time range is considered to cross midnight if
 30    /// </summary>
 3031    public bool CrossesMidnight => End!.Value.Value < Start!.Value.Value;
 32
 33    /// <summary>
 34    /// Determines whether a given <see cref="TimeOnly"/> value falls within this closed (inclusive) time range.
 35    /// Both the start and end bounds are inclusive. If the range does not cross midnight, the value must be
 36    /// greater than or equal to the start and less than or equal to the end. If the range crosses midnight,
 37    /// the value must be greater than or equal to the start or less than or equal to the end.
 38    /// </summary>
 39    /// <param name="value">The TimeOnly value to check.</param>
 40    /// <returns><c>true</c> if the value falls within the time range; otherwise, <c>false</c>.</returns>
 41    public override bool Contains(TimeOnly value)
 942        => !CrossesMidnight ? base.Contains(value) : value >= Start!.Value.Value || value <= End!.Value.Value;
 43
 44    /// <inheritdoc />
 045    protected override TimeRange Create(IntervalBoundary<TimeOnly>? start, IntervalBoundary<TimeOnly>? end) => !start.Ha
 046        ? throw new InvalidOperationException("TimeRange must be bounded.")
 047        : !start.Value.IsInclusive || !end.Value.IsInclusive
 048            ? throw new InvalidOperationException("TimeRange only supports inclusive boundaries.")
 049            : new TimeRange(start.Value.Value, end.Value.Value);
 50}
 51