< Summary

Information
Class: MyNet.Temporal.Intervals.DateTimeInterval<T>
Assembly: MyNet.Temporal
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/Intervals/DateTimeInterval.cs
Tag: 342_31701152804
Line coverage
75%
Covered lines: 9
Uncovered lines: 3
Coverable lines: 12
Total lines: 62
Line coverage: 75%
Branch coverage
50%
Covered branches: 10
Total branches: 20
Branch coverage: 50%
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%
IsCurrent(...)100%11100%
IsPast(...)66.66%7675%
IsFuture(...)66.66%7675%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/Intervals/DateTimeInterval.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DateTimeInterval.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/// Base class for intervals of <see cref="DateTime"/> (civil / UI time with explicit <see cref="DateTime.Kind"/>).
 15/// Default boundary policy is half-open <c>[start, end)</c> when subclasses do not override inclusivity.
 16/// Absolute (API / domain) instants should use <c>DateTimeOffset</c>-based interval types instead.
 17/// </summary>
 18/// <typeparam name="TSelf">The concrete interval type.</typeparam>
 19/// <param name="start">Optional start instant.</param>
 20/// <param name="end">Optional end instant.</param>
 21/// <param name="inclusiveStart">Whether the start bound is inclusive.</param>
 22/// <param name="inclusiveEnd">Whether the end bound is inclusive.</param>
 23public abstract class DateTimeInterval<TSelf>(DateTime? start, DateTime? end, bool inclusiveStart = true, bool inclusive
 11724    : Interval<DateTime, TSelf>(start.HasValue ? new IntervalBoundary<DateTime>(start.Value, inclusiveStart) : null,
 11725        end.HasValue ? new IntervalBoundary<DateTime>(end.Value, inclusiveEnd) : null), IDateTimeInterval
 26    where TSelf : DateTimeInterval<TSelf>
 27{
 28    /// <inheritdoc />
 029    public TimeSpan? Duration => !HasStart || !HasEnd ? null : End!.Value.Value - Start!.Value.Value;
 30
 31    /// <summary>
 32    /// Returns whether <paramref name="now"/> lies inside this interval (respecting inclusivity).
 33    /// </summary>
 334    public bool IsCurrent(DateTime now) => Contains(now);
 35
 36    /// <summary>
 37    /// Returns whether <paramref name="now"/> is strictly after this interval.
 38    /// </summary>
 39    public bool IsPast(DateTime now)
 40    {
 1241        if (!HasEnd)
 042            return false;
 43
 1244        var comparison = End!.Value.Value.CompareTo(now);
 45
 1246        return comparison < 0 || (comparison == 0 && !End.Value.IsInclusive);
 47    }
 48
 49    /// <summary>
 50    /// Returns whether <paramref name="now"/> is strictly before this interval.
 51    /// </summary>
 52    public bool IsFuture(DateTime now)
 53    {
 954        if (!HasStart)
 055            return false;
 56
 957        var comparison = Start!.Value.Value.CompareTo(now);
 58
 959        return comparison > 0 || (comparison == 0 && !Start.Value.IsInclusive);
 60    }
 61}
 62