< Summary

Information
Class: MyNet.Temporal.Intervals.DateRange
Assembly: MyNet.Temporal
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/Intervals/DateRange.cs
Tag: 342_31701152804
Line coverage
57%
Covered lines: 8
Uncovered lines: 6
Coverable lines: 14
Total lines: 58
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/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/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
 10using MyNet.Primitives.Intervals;
 11
 12namespace MyNet.Temporal.Intervals;
 13
 14/// <summary>
 15/// Represents a closed interval of dates, defined by a start and an end date. The interval includes both the start and 
 16/// </summary>
 17/// <param name="start">The start date of the interval.</param>
 18/// <param name="end">The end date of the interval.</param>
 4219public sealed class DateRange(DateOnly start, DateOnly end) : Interval<DateOnly, DateRange>(new IntervalBoundary<DateOnl
 20{
 21    /// <summary>
 22    /// Gets the number of days in the date range, including both the start and end dates.
 23    /// </summary>
 624    public int DayCount => End!.Value.Value.DayNumber - Start!.Value.Value.DayNumber + 1;
 25
 26    /// <inheritdoc />
 27    protected override DateRange Create(IntervalBoundary<DateOnly>? start, IntervalBoundary<DateOnly>? end) =>
 028        !start.HasValue || !end.HasValue
 029            ? throw new InvalidOperationException("DateRange must be bounded.")
 030            : !start.Value.IsInclusive || !end.Value.IsInclusive
 031                ? throw new InvalidOperationException("DateRange only supports inclusive boundaries.")
 032                : new DateRange(start.Value.Value, end.Value.Value);
 33
 34    /// <summary>
 35    /// Enumerates all the dates in the date range, starting from the start date and ending with the end date. Each date
 36    /// </summary>
 37    /// <returns>An enumerable collection of DateOnly values representing each day in the date range.</returns>
 38    public IEnumerable<DateOnly> EnumerateDays()
 39    {
 340        for (var date = Start!.Value.Value;
 1241             date <= End!.Value.Value;
 942             date = date.AddDays(1))
 43        {
 944            yield return date;
 45        }
 346    }
 47
 48    /// <summary>
 49    /// Gets the start and end boundaries of the date range as <see cref="IntervalBoundary{DateOnly}"/> values. The star
 50    /// </summary>
 351    IntervalBoundary<DateOnly> IBoundedInterval<DateOnly>.Start => Start!.Value;
 52
 53    /// <summary>
 54    /// Gets the start and end boundaries of the date range as <see cref="IntervalBoundary{DateOnly}"/> values. The star
 55    /// </summary>
 056    IntervalBoundary<DateOnly> IBoundedInterval<DateOnly>.End => End!.Value;
 57}
 58