< Summary

Information
Class: MyNet.Temporal.Intervals.DateTimeRange
Assembly: MyNet.Temporal
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/Intervals/DateTimeRange.cs
Tag: 342_31701152804
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 53
Line coverage: 100%
Branch coverage
66%
Covered branches: 8
Total branches: 12
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Enumerate()75%88100%
Create(...)50%44100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DateTimeRange.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9
 10using MyNet.Primitives.Intervals;
 11
 12namespace MyNet.Temporal.Intervals;
 13
 14/// <summary>
 15/// Configurable civil <see cref="DateTime"/> interval. Defaults to half-open <c>[start, end)</c>.
 16/// Use <see cref="DateTimePeriod"/> when the half-open contract must be enforced; use this type when
 17/// inclusivity is caller-defined. <see cref="DateTime.Kind"/> is not normalized.
 18/// </summary>
 19/// <param name="start">Start bound.</param>
 20/// <param name="end">End bound.</param>
 21/// <param name="inclusiveStart">Whether start is inclusive (default true).</param>
 22/// <param name="inclusiveEnd">Whether end is inclusive (default false).</param>
 23public sealed class DateTimeRange(DateTime start, DateTime end, bool inclusiveStart = true, bool inclusiveEnd = false)
 2124    : DateTimeInterval<DateTimeRange>(start, end, inclusiveStart, inclusiveEnd)
 25{
 26    /// <summary>
 27    /// Enumerates values from start to end using a fixed <paramref name="step"/>.
 28    /// </summary>
 29    /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="step"/> is not positive.</exception>
 30    public IEnumerable<DateTime> Enumerate(TimeSpan step)
 31    {
 332        ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(step, TimeSpan.Zero);
 33
 334        var current = Start!.Value.Value;
 335        if (!Start.Value.IsInclusive)
 36        {
 337            current += step;
 38        }
 39
 940        while (current < End!.Value.Value || (End.Value.IsInclusive && current == End.Value.Value))
 41        {
 642            yield return current;
 643            current += step;
 44        }
 345    }
 46
 47    /// <inheritdoc />
 48    protected override DateTimeRange Create(IntervalBoundary<DateTime>? start, IntervalBoundary<DateTime>? end) =>
 349        !start.HasValue || !end.HasValue
 350            ? throw new InvalidOperationException("DateTimeRange must be bounded.")
 351            : new DateTimeRange(start.Value.Value, end.Value.Value, start.Value.IsInclusive, end.Value.IsInclusive);
 52}
 53