< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Enumerate()0%7280%
Create(...)0%2040%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DateTimeOffsetRange.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 absolute <see cref="DateTimeOffset"/> interval. Defaults to half-open <c>[start, end)</c>.
 16/// Use <see cref="DateTimeOffsetPeriod"/> when the half-open contract must be enforced; use this type when
 17/// inclusivity is caller-defined.
 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 DateTimeOffsetRange(DateTimeOffset start, DateTimeOffset end, bool inclusiveStart = true, bool inclu
 024    : DateTimeOffsetInterval<DateTimeOffsetRange>(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<DateTimeOffset> Enumerate(TimeSpan step)
 31    {
 032        ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(step, TimeSpan.Zero);
 33
 034        var current = Start!.Value.Value;
 035        if (!Start.Value.IsInclusive)
 36        {
 037            current += step;
 38        }
 39
 040        while (current < End!.Value.Value || (End.Value.IsInclusive && current == End.Value.Value))
 41        {
 042            yield return current;
 043            current += step;
 44        }
 045    }
 46
 47    /// <inheritdoc />
 48    protected override DateTimeOffsetRange Create(IntervalBoundary<DateTimeOffset>? start, IntervalBoundary<DateTimeOffs
 049        !start.HasValue || !end.HasValue
 050            ? throw new InvalidOperationException("DateTimeOffsetRange must be bounded.")
 051            : new DateTimeOffsetRange(start.Value.Value, end.Value.Value, start.Value.IsInclusive, end.Value.IsInclusive
 52}
 53