< Summary

Information
Class: MyNet.Primitives.TimeRangeExtensions
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Temporal/Extensions/TimeRangeExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 57
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Shift(...)100%11100%
Expand(...)100%11100%
Enumerate()100%22100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Temporal/Extensions/TimeRangeExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TimeRangeExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using MyNet.Primitives.Intervals;
 10
 11#pragma warning disable IDE0130 // Namespace does not match folder structure
 12namespace MyNet.Primitives;
 13#pragma warning restore IDE0130 // Namespace does not match folder structure
 14
 15public static class TimeRangeExtensions
 16{
 17    extension(TimeRange left)
 18    {
 19        /// <summary>
 20        /// Shifts the time range by a specified offset, effectively moving the entire range forward or backward in time
 21        /// </summary>
 22        /// <param name="offset">The time span to shift the time range by.</param>
 23        /// <returns>A new time range shifted by the specified offset.</returns>
 324        public TimeRange Shift(TimeSpan offset) => new(left.Start!.Value.Value.Add(offset), left.End!.Value.Value.Add(of
 25
 26        /// <summary>
 27        /// Expands the time range by a specified duration, effectively increasing the length of the range by adding the
 28        /// </summary>
 29        /// <param name="duration">The duration to expand the time range by.</param>
 30        /// <returns>A new time range expanded by the specified duration.</returns>
 331        public TimeRange Expand(TimeSpan duration) => new(left.Start!.Value.Value.Add(-duration), left.End!.Value.Value.
 32
 33        /// <summary>
 34        /// Enumerates the time values within the time range at specified intervals defined by the step parameter. This 
 35        /// </summary>
 36        /// <param name="step">The time span to use as the interval between each enumerated time value.</param>
 37        /// <returns>An enumerable sequence of TimeOnly values within the time range.</returns>
 38        /// <exception cref="ArgumentOutOfRangeException">Thrown when the step is less than or equal to zero.</exception
 39        public IEnumerable<TimeOnly> Enumerate(TimeSpan step)
 40        {
 641            ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(step, TimeSpan.Zero);
 42
 343            var current = left.Start!.Value.Value;
 344            var elapsed = TimeSpan.Zero;
 45
 346            yield return current;
 47
 1548            while (elapsed + step <= left.Duration)
 49            {
 1250                current = current.Add(step);
 1251                elapsed += step;
 1252                yield return current;
 53            }
 354        }
 55    }
 56}
 57