< Summary

Information
Class: MyNet.Primitives.Intervals.Period
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Intervals/Period.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
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%
FromDuration(...)100%11100%
Shift(...)100%11100%
Extend(...)100%11100%
Create(...)75%88100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="Period.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8
 9namespace MyNet.Primitives.Intervals;
 10
 11/// <summary>
 12/// Represents a closed temporal interval where both the start and end boundaries are defined and are inclusive. This cl
 13/// </summary>
 14/// <param name="start">The start DateTime of the interval.</param>
 15/// <param name="end">The end DateTime of the interval.</param>
 8116public sealed class Period(DateTime start, DateTime end) : TemporalInterval<Period>(start, end, inclusiveStart: true, in
 17{
 18    /// <summary>
 19    /// Creates a new instance of the <see cref="Period"/> class based on a specified start DateTime and a duration repr
 20    /// </summary>
 21    /// <param name="start">The start DateTime of the period.</param>
 22    /// <param name="duration">The duration of the period.</param>
 23    /// <returns>A new instance of the <see cref="Period"/> class.</returns>
 324    public static Period FromDuration(DateTime start, TimeSpan duration) => new(start, start + duration);
 25
 26    /// <summary>
 27    /// Shifts the period by a specified TimeSpan offset, creating a new period that starts and ends at times that are o
 28    /// </summary>
 29    /// <param name="offset">The TimeSpan offset to apply to the period.</param>
 30    /// <returns>A new instance of the <see cref="Period"/> class with the shifted start and end times.</returns>
 931    public Period Shift(TimeSpan offset) => new(Start!.Value.Value + offset, End!.Value.Value + offset);
 32
 33    /// <summary>
 34    /// Extends the period by a specified TimeSpan offset, creating a new period that starts at the original start time 
 35    /// </summary>
 36    /// <param name="offset">The TimeSpan offset to apply to the end of the period.</param>
 37    /// <returns>A new instance of the <see cref="Period"/> class with the extended end time.</returns>
 638    public Period Extend(TimeSpan offset) => new(Start!.Value.Value, End!.Value.Value + offset);
 39
 40    /// <inheritdoc />
 41    protected override Period Create(IntervalBoundary<DateTime>? start, IntervalBoundary<DateTime>? end) =>
 642        !start.HasValue || !end.HasValue
 643            ? throw new InvalidOperationException("Period must be bounded.")
 644            : !start.Value.IsInclusive || end.Value.IsInclusive
 645                ? throw new InvalidOperationException("Period only supports [start, end) boundaries.")
 646                : new(start.Value.Value, end.Value.Value);
 47}
 48