< Summary

Information
Class: MyNet.Primitives.Intervals.DateTimeRange
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Intervals/DateTimeRange.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 48
Line coverage: 100%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
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(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/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
 10namespace MyNet.Primitives.Intervals;
 11
 12/// <summary>
 13/// Represents a closed interval of date and time, defined by a start and an end DateTime. The interval can be configure
 14/// </summary>
 15/// <param name="start">The start DateTime of the interval.</param>
 16/// <param name="end">The end DateTime of the interval.</param>
 17/// <param name="inclusiveStart">Indicates whether the start DateTime is inclusive.</param>
 18/// <param name="inclusiveEnd">Indicates whether the end DateTime is inclusive.</param>
 2119public sealed class DateTimeRange(DateTime start, DateTime end, bool inclusiveStart = true, bool inclusiveEnd = false) :
 20{
 21    /// <summary>
 22    /// Enumerates the DateTime values within the range at regular intervals defined by the specified step. The method t
 23    /// </summary>
 24    /// <param name="step">The interval between each enumerated DateTime value.</param>
 25    /// <returns>An enumerable collection of DateTime values within the range.</returns>
 26    /// <exception cref="ArgumentOutOfRangeException">Thrown when the step is less than or equal to zero.</exception>
 27    public IEnumerable<DateTime> Enumerate(TimeSpan step)
 28    {
 329        ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(step, TimeSpan.Zero);
 30
 331        var current = Start!.Value.Value;
 332        if (!Start.Value.IsInclusive)
 33        {
 334            current += step;
 35        }
 36
 937        while (current < End!.Value.Value || (End.Value.IsInclusive && current == End.Value.Value))
 38        {
 639            yield return current;
 640            current += step;
 41        }
 342    }
 43
 44    /// <inheritdoc />
 45    protected override DateTimeRange Create(IntervalBoundary<DateTime>? start, IntervalBoundary<DateTime>? end)
 346        => new(start!.Value.Value, end!.Value.Value, start.Value.IsInclusive, end.Value.IsInclusive);
 47}
 48