< Summary

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

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DateTimeOffsetInterval.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="DateTimeOffset"/> (absolute instants with offset).
 15/// Default boundary policy is half-open <c>[start, end)</c> when subclasses do not override inclusivity.
 16/// Civil / UI time without a reliable offset should use <see cref="DateTimeInterval{TSelf}"/> 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 DateTimeOffsetInterval<TSelf>(DateTimeOffset? start, DateTimeOffset? end, bool inclusiveStart = tr
 3624    : Interval<DateTimeOffset, TSelf>(start.HasValue ? new IntervalBoundary<DateTimeOffset>(start.Value, inclusiveStart)
 3625        end.HasValue ? new IntervalBoundary<DateTimeOffset>(end.Value, inclusiveEnd) : null), IDateTimeOffsetInterval
 26    where TSelf : DateTimeOffsetInterval<TSelf>
 27{
 28    /// <inheritdoc />
 629    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>
 034    public bool IsCurrent(DateTimeOffset now) => Contains(now);
 35
 36    /// <summary>
 37    /// Returns whether <paramref name="now"/> is strictly after this interval.
 38    /// </summary>
 39    public bool IsPast(DateTimeOffset now)
 40    {
 041        if (!HasEnd)
 042            return false;
 43
 044        var comparison = End!.Value.Value.CompareTo(now);
 45
 046        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(DateTimeOffset now)
 53    {
 054        if (!HasStart)
 055            return false;
 56
 057        var comparison = Start!.Value.Value.CompareTo(now);
 58
 059        return comparison > 0 || (comparison == 0 && !Start.Value.IsInclusive);
 60    }
 61}
 62