< Summary

Information
Class: MyNet.Temporal.Decomposition.TimeSpanDecompositionExtensions
Assembly: MyNet.Temporal
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Temporal/Decomposition/Extensions/TimeSpanDecompositionExtensions.cs
Tag: 323_28699572109
Line coverage
50%
Covered lines: 13
Uncovered lines: 13
Coverable lines: 26
Total lines: 156
Line coverage: 50%
Branch coverage
25%
Covered branches: 2
Total branches: 8
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Decompose(...)100%210%
Decompose(...)100%11100%
Decompose(...)100%11100%
Decompose(...)100%210%
Decompose(...)100%210%
Humanized(...)100%11100%
Compact(...)100%11100%
Full(...)100%11100%
Largest(...)100%11100%
Largest(...)50%22100%
Largest(...)0%620%
Smallest(...)100%210%
Smallest(...)50%22100%
Smallest(...)0%620%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Temporal/Decomposition/Extensions/TimeSpanDecompositionExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TimeSpanDecompositionExtensions.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;
 10
 11#pragma warning disable IDE0130 // Namespace does not match folder structure
 12namespace MyNet.Temporal.Decomposition;
 13#pragma warning restore IDE0130 // Namespace does not match folder structure
 14
 15public static class TimeSpanDecompositionExtensions
 16{
 17    extension(TimeSpan timeSpan)
 18    {
 19        /// <summary>
 20        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 21        /// </summary>
 22        /// <returns>A list of <see cref="TimeUnitValue"/> objects representing the value of each time unit in the decom
 023        public IReadOnlyList<TimeUnitValue> Decompose() => timeSpan.Decompose(TimeSpanDecompositionPresets.Humanized);
 24
 25        /// <summary>
 26        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 27        /// </summary>
 28        /// <param name="options">The options to use for the decomposition.</param>
 29        /// <returns>A list of <see cref="TimeUnitValue"/> objects representing the value of each time unit in the decom
 33630        public IReadOnlyList<TimeUnitValue> Decompose(TimeSpanDecompositionOptions options) => TimeSpanDecomposer.Defaul
 31
 32        /// <summary>
 33        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 34        /// </summary>
 35        /// <param name="configure">The configuration action to customize the decomposition.</param>
 36        /// <returns>A list of <see cref="TimeUnitValue"/> objects representing the value of each time unit in the decom
 37        public IReadOnlyList<TimeUnitValue> Decompose(Action<TimeSpanDecompositionBuilder> configure)
 38        {
 639            ArgumentNullException.ThrowIfNull(configure);
 40
 641            var builder = new TimeSpanDecompositionBuilder(TimeSpanDecomposer.Default, timeSpan);
 642            configure(builder);
 43
 644            return builder.Decompose();
 45        }
 46
 47        /// <summary>
 48        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 49        /// </summary>
 50        /// <param name="decomposer">The custom decomposer to use for the decomposition.</param>
 51        /// <param name="options">The options to use for the decomposition.</param>
 52        /// <returns>A list of <see cref="TimeUnitValue"/> objects representing the value of each time unit in the decom
 53        public IReadOnlyList<TimeUnitValue> Decompose(ITimeSpanDecomposer decomposer, TimeSpanDecompositionOptions optio
 54        {
 055            ArgumentNullException.ThrowIfNull(decomposer);
 056            return decomposer.Decompose(timeSpan, options);
 57        }
 58
 59        /// <summary>
 60        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 61        /// </summary>
 62        /// <param name="decomposer">The custom decomposer to use for the decomposition.</param>
 63        /// <param name="configure">The configuration action to customize the decomposition.</param>
 64        /// <returns>A list of <see cref="TimeUnitValue"/> objects representing the value of each time unit in the decom
 65        public IReadOnlyList<TimeUnitValue> Decompose(ITimeSpanDecomposer decomposer, Action<TimeSpanDecompositionBuilde
 66        {
 067            ArgumentNullException.ThrowIfNull(decomposer);
 068            ArgumentNullException.ThrowIfNull(configure);
 69
 070            var builder = new TimeSpanDecompositionBuilder(decomposer, timeSpan);
 71
 072            configure(builder);
 73
 074            return builder.Decompose();
 75        }
 76
 77        /// <summary>
 78        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 79        /// </summary>
 80        /// <returns>A list of <see cref="TimeUnitValue"/> objects representing the value of each time unit in the decom
 381        public IReadOnlyList<TimeUnitValue> Humanized() => timeSpan.Decompose(TimeSpanDecompositionPresets.Humanized);
 82
 83        /// <summary>
 84        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 85        /// </summary>
 86        /// <returns>A list of <see cref="TimeUnitValue"/> objects representing the value of each time unit in the decom
 387        public IReadOnlyList<TimeUnitValue> Compact() => timeSpan.Decompose(TimeSpanDecompositionPresets.Compact);
 88
 89        /// <summary>
 90        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 91        /// </summary>
 92        /// <returns>A list of <see cref="TimeUnitValue"/> objects representing the value of each time unit in the decom
 393        public IReadOnlyList<TimeUnitValue> Full() => timeSpan.Decompose(TimeSpanDecompositionPresets.Full);
 94
 95        /// <summary>
 96        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 97        /// </summary>
 98        /// <returns>A <see cref="TimeUnitValue"/> object representing the value of the largest time unit in the decompo
 399        public TimeUnitValue Largest() => timeSpan.Largest(TimeSpanDecompositionPresets.LargestUnit);
 100
 101        /// <summary>
 102        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 103        /// </summary>
 104        /// <param name="options">The options to customize the decomposition.</param>
 105        /// <returns>A <see cref="TimeUnitValue"/> object representing the value of the largest time unit in the decompo
 106        public TimeUnitValue Largest(TimeSpanDecompositionOptions options)
 107        {
 3108            var result = timeSpan.Decompose(options);
 109
 3110            return result.Count > 0 ? result[0] : new(0, options.MinUnit);
 111        }
 112
 113        /// <summary>
 114        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 115        /// </summary>
 116        /// <param name="configure">A delegate to configure the decomposition options.</param>
 117        /// <returns>A <see cref="TimeUnitValue"/> object representing the value of the largest time unit in the decompo
 118        public TimeUnitValue Largest(Action<TimeSpanDecompositionBuilder> configure)
 119        {
 0120            var result = timeSpan.Decompose(configure);
 121
 0122            return result.Count > 0 ? result[0] : new(0, TimeUnit.Millisecond);
 123        }
 124
 125        /// <summary>
 126        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 127        /// </summary>
 128        /// <returns>A <see cref="TimeUnitValue"/> object representing the value of the smallest time unit in the decomp
 0129        public TimeUnitValue Smallest() => timeSpan.Largest(TimeSpanDecompositionPresets.SmallestUnit);
 130
 131        /// <summary>
 132        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 133        /// </summary>
 134        /// <param name="options">The options to customize the decomposition.</param>
 135        /// <returns>A <see cref="TimeUnitValue"/> object representing the value of the smallest time unit in the decomp
 136        public TimeUnitValue Smallest(TimeSpanDecompositionOptions options)
 137        {
 3138            var result = timeSpan.Decompose(options);
 139
 3140            return result.Count > 0 ? result[^1] : new(0, options.MinUnit);
 141        }
 142
 143        /// <summary>
 144        /// Decomposes the <see cref="TimeSpan"/> into its constituent time units (e.g., years, months, days, hours, min
 145        /// </summary>
 146        /// <param name="configure">A delegate to configure the decomposition options.</param>
 147        /// <returns>A <see cref="TimeUnitValue"/> object representing the value of the smallest time unit in the decomp
 148        public TimeUnitValue Smallest(Action<TimeSpanDecompositionBuilder> configure)
 149        {
 0150            var result = timeSpan.Decompose(configure);
 151
 0152            return result.Count > 0 ? result[^1] : new(0, TimeUnit.Millisecond);
 153        }
 154    }
 155}
 156