< Summary

Information
Class: MyNet.Humanizer.Facade.TimeHumanizerExtensions
Assembly: MyNet.Humanizer
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Humanizer/Facade/Extensions/TimeHumanizerExtensions.cs
Tag: 323_28699572109
Line coverage
92%
Covered lines: 13
Uncovered lines: 1
Coverable lines: 14
Total lines: 57
Line coverage: 92.8%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Humanize(...)100%11100%
Humanize(...)83.33%6688.88%
Humanize(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Humanizer/Facade/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 System.Globalization;
 9using MyNet.Globalization.Facade;
 10using MyNet.Humanizer.Temporal;
 11using MyNet.Temporal.Decomposition;
 12
 13#pragma warning disable IDE0130 // Namespace does not match folder structure
 14namespace MyNet.Humanizer.Facade;
 15#pragma warning restore IDE0130 // Namespace does not match folder structure
 16
 17public static class TimeHumanizerExtensions
 18{
 19    extension(TimeSpan timeSpan)
 20    {
 21        /// <summary>
 22        /// Humanizes the time span using default options.
 23        /// </summary>
 324        public string Humanize(CultureInfo? culture = null) => timeSpan.Humanize(TimeHumanizationPresets.Default, cultur
 25
 26        /// <summary>
 27        /// Humanizes the time span using the specified options.
 28        /// </summary>
 29        public string Humanize(TimeHumanizationOptions options, CultureInfo? culture = null)
 30        {
 29131            ArgumentNullException.ThrowIfNull(options);
 32
 29133            var decompositionOptions = options.ToDecompositionOptions();
 34
 29135            var decomposition = timeSpan.Decompose(decompositionOptions);
 36
 29137            return options.Mode switch
 29138                {
 939                    TimeHumanizationMode.Duration => Localizer.ForCulture(culture).GetRequired<ITimeHumanizer>().Humaniz
 28240                    TimeHumanizationMode.Relative => Localizer.ForCulture(culture).GetRequired<ITimeHumanizer>().Humaniz
 041                    _ => string.Empty
 29142                };
 43        }
 44
 45        public string Humanize(Action<TimeHumanizationBuilder> configure, CultureInfo? culture = null)
 46        {
 347            ArgumentNullException.ThrowIfNull(configure);
 48
 349            var builder = new TimeHumanizationBuilder();
 50
 351            configure(builder);
 52
 353            return timeSpan.Humanize(builder.Build(), culture);
 54        }
 55    }
 56}
 57