< Summary

Information
Class: MyNet.Primitives.Intervals.DateRange
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Intervals/DateRange.cs
Tag: 323_28699572109
Line coverage
57%
Covered lines: 8
Uncovered lines: 6
Coverable lines: 14
Total lines: 56
Line coverage: 57.1%
Branch coverage
20%
Covered branches: 2
Total branches: 10
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(...)100%11100%
get_DayCount()100%11100%
Create(...)0%7280%
EnumerateDays()100%22100%
MyNet.Primitives.Intervals.IBoundedInterval<System.DateOnly>.get_Start()100%11100%
MyNet.Primitives.Intervals.IBoundedInterval<System.DateOnly>.get_End()100%210%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DateRange.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 dates, defined by a start and an end date. The interval includes both the start and 
 14/// </summary>
 15/// <param name="start">The start date of the interval.</param>
 16/// <param name="end">The end date of the interval.</param>
 3917public sealed class DateRange(DateOnly start, DateOnly end) : Interval<DateOnly, DateRange>(new IntervalBoundary<DateOnl
 18{
 19    /// <summary>
 20    /// Gets the number of days in the date range, including both the start and end dates.
 21    /// </summary>
 322    public int DayCount => End!.Value.Value.DayNumber - Start!.Value.Value.DayNumber + 1;
 23
 24    /// <inheritdoc />
 25    protected override DateRange Create(IntervalBoundary<DateOnly>? start, IntervalBoundary<DateOnly>? end) =>
 026        !start.HasValue || !end.HasValue
 027            ? throw new InvalidOperationException("DateRange must be bounded.")
 028            : !start.Value.IsInclusive || !end.Value.IsInclusive
 029                ? throw new InvalidOperationException("DateRange only supports inclusive boundaries.")
 030                : new(start.Value.Value, end.Value.Value);
 31
 32    /// <summary>
 33    /// Enumerates all the dates in the date range, starting from the start date and ending with the end date. Each date
 34    /// </summary>
 35    /// <returns>An enumerable collection of DateOnly values representing each day in the date range.</returns>
 36    public IEnumerable<DateOnly> EnumerateDays()
 37    {
 338        for (var date = Start!.Value.Value;
 1239             date <= End!.Value.Value;
 940             date = date.AddDays(1))
 41        {
 942            yield return date;
 43        }
 344    }
 45
 46    /// <summary>
 47    /// Gets the start and end boundaries of the date range as <see cref="IntervalBoundary{DateOnly}"/> values. The star
 48    /// </summary>
 349    IntervalBoundary<DateOnly> IBoundedInterval<DateOnly>.Start => Start!.Value;
 50
 51    /// <summary>
 52    /// Gets the start and end boundaries of the date range as <see cref="IntervalBoundary{DateOnly}"/> values. The star
 53    /// </summary>
 054    IntervalBoundary<DateOnly> IBoundedInterval<DateOnly>.End => End!.Value;
 55}
 56