< Summary

Information
Class: NtpServiceLibrary.TimeSpanExtension
Assembly: NtpServiceLibrary
File(s): D:\a\ntp-service\ntp-service\NtpServiceLibrary\TimeSpanExtension.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 37
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
Format(...)100%11100%
Suffix(...)100%22100%

File(s)

D:\a\ntp-service\ntp-service\NtpServiceLibrary\TimeSpanExtension.cs

#LineLine coverage
 1using System;
 2
 3namespace NtpServiceLibrary
 4{
 5    /// <summary>
 6    /// Provides extension methods for the <see cref="TimeSpan"/> structure.
 7    /// </summary>
 8    public static class TimeSpanExtension
 9    {
 10        /// <summary>
 11        /// Formats the <see cref="TimeSpan"/> into a human-readable string
 12        /// with correct pluralization for hours, minutes, and seconds.
 13        /// </summary>
 14        /// <param name="timespan">The <see cref="TimeSpan"/> to format.</param>
 15        /// <returns>
 16        /// A string in the format "X hour(s) Y minute(s) Z second(s)".
 17        /// </returns>
 18        public static string Format(this TimeSpan timespan)
 419        {
 420            return string.Format("{0} hour{1} {2} minute{3} {4} second{5}",
 421                timespan.Hours, Suffix(timespan.Hours),
 422                timespan.Minutes, Suffix(timespan.Minutes),
 423                timespan.Seconds, Suffix(timespan.Seconds)
 424                );
 425        }
 26
 27        /// <summary>
 28        /// Returns the plural suffix "s" if the value is not 1.
 29        /// </summary>
 30        /// <param name="value">The numeric value to check.</param>
 31        /// <returns>"s" if value is not 1; otherwise, an empty string.</returns>
 32        private static string Suffix(int value)
 1233        {
 1234            return value != 1 ? "s" : "";
 1235        }
 36    }
 37}