< Summary

Information
Class: MyNet.Primitives.Intervals.TemporalInterval<T>
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Intervals/TemporalInterval.cs
Tag: 323_28699572109
Line coverage
61%
Covered lines: 8
Uncovered lines: 5
Coverable lines: 13
Total lines: 70
Line coverage: 61.5%
Branch coverage
54%
Covered branches: 12
Total branches: 22
Branch coverage: 54.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%44100%
get_Duration()0%2040%
MyNet.Primitives.Intervals.ITemporalInterval.get_Duration()0%620%
IsCurrent(...)100%210%
IsPast(...)83.33%7675%
IsFuture(...)83.33%7675%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TemporalInterval.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 temporal interval defined by optional start and end DateTime boundaries. This class extends the generic
 13/// </summary>
 14/// <param name="start">The start DateTime of the interval.</param>
 15/// <param name="end">The end DateTime of the interval.</param>
 16/// <param name="inclusiveStart">Indicates whether the start boundary is inclusive.</param>
 17/// <param name="inclusiveEnd">Indicates whether the end boundary is inclusive.</param>
 18public abstract class TemporalInterval<TSelf>(DateTime? start, DateTime? end, bool inclusiveStart = true, bool inclusive
 10219    : Interval<DateTime, TSelf>(start.HasValue ? new IntervalBoundary<DateTime>(start.Value, inclusiveStart) : null,
 10220        end.HasValue ? new IntervalBoundary<DateTime>(end.Value, inclusiveEnd) : null), ITemporalInterval
 21    where TSelf : TemporalInterval<TSelf>
 22{
 23    /// <summary>
 24    /// Gets the duration of the interval as a TimeSpan. If either the start or end boundary is not defined, this proper
 25    /// </summary>
 026    public TimeSpan? Duration => !HasStart || !HasEnd ? null : End!.Value.Value - Start!.Value.Value;
 27
 28    /// <summary>
 29    /// Gets the duration of the interval as a TimeSpan. If the duration cannot be calculated because either the start o
 30    /// </summary>
 031    TimeSpan ITemporalInterval.Duration => Duration ?? TimeSpan.MaxValue;
 32
 33    /// <summary>
 34    /// Determines whether the specified DateTime value falls within the interval. This method checks if the value is gr
 35    /// </summary>
 36    /// <param name="now">The DateTime value to check.</param>
 37    /// <returns>True if the value is within the interval; otherwise, false.</returns>
 038    public bool IsCurrent(DateTime now) => Contains(now);
 39
 40    /// <summary>
 41    /// Determines whether the specified DateTime value is in the past relative to the interval. This method checks if t
 42    /// </summary>
 43    /// <param name="now">The DateTime value to check.</param>
 44    /// <returns>True if the value is in the past relative to the interval; otherwise, false.</returns>
 45    public bool IsPast(DateTime now)
 46    {
 1247        if (!HasEnd)
 048            return false;
 49
 1250        var comparison = End!.Value.Value.CompareTo(now);
 51
 1252        return comparison < 0 || (comparison == 0 && !End.Value.IsInclusive);
 53    }
 54
 55    /// <summary>
 56    /// Determines whether the specified DateTime value is in the future relative to the interval. This method checks if
 57    /// </summary>
 58    /// <param name="now">The DateTime value to check.</param>
 59    /// <returns>True if the value is in the future relative to the interval; otherwise, false.</returns>
 60    public bool IsFuture(DateTime now)
 61    {
 962        if (!HasStart)
 063            return false;
 64
 965        var comparison = Start!.Value.Value.CompareTo(now);
 66
 967        return comparison > 0 || (comparison == 0 && !Start.Value.IsInclusive);
 68    }
 69}
 70