< Summary

Information
Class: MyNet.Humanizer.TimeHumanizerExtensions
Assembly: MyNet.Humanizer
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Humanizer/Extensions/TimeHumanizerExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 51
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
Tense(...)100%22100%
ToDecompositionOptions(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Humanizer/Extensions/TimeHumanizerExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TimeHumanizerExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using MyNet.Humanizer.Temporal;
 9using MyNet.Temporal.Decomposition;
 10
 11#pragma warning disable IDE0130 // Namespace does not match folder structure
 12namespace MyNet.Humanizer;
 13#pragma warning restore IDE0130 // Namespace does not match folder structure
 14
 15public static class TimeHumanizerExtensions
 16{
 17    extension(TimeSpan timeSpan)
 18    {
 19        /// <summary>
 20        /// Infers the tense from the specified time span.
 21        /// </summary>
 22        /// <returns>
 23        /// <see cref="Tense.Future"/> when the span is positive or zero;
 24        /// otherwise <see cref="Tense.Past"/>.
 25        /// </returns>
 1826        public Tense Tense() => timeSpan >= TimeSpan.Zero ? Temporal.Tense.Future : Temporal.Tense.Past;
 27    }
 28
 29    extension(TimeHumanizationOptions options)
 30    {
 31        /// <summary>
 32        /// Converts humanization options to decomposition options.
 33        /// </summary>
 34        /// <returns>The corresponding decomposition options.</returns>
 35        public TimeSpanDecompositionOptions ToDecompositionOptions()
 36        {
 29437            ArgumentNullException.ThrowIfNull(options);
 38
 29439            return new()
 29440            {
 29441                MinUnit = options.MinUnit,
 29442                MaxUnit = options.MaxUnit,
 29443                Mode = options.DecompositionMode,
 29444                MaxComponents = options.MaxComponents,
 29445                IncludeZeroUnits = options.IncludeZeroUnits,
 29446                Quantizer = options.Quantizer
 29447            };
 48        }
 49    }
 50}
 51