コード例 #1
0
        /// <summary>
        /// Formats a string from a given timespan to a nice, human readable,
        /// based on the most prominent unit set in the span.
        /// </summary>
        /// <param name="span">The timespan to format.</param>
        /// <returns>A pleasant string.</returns>
        public static string ToHumanReadableString(this STimeSpan span)
        {
            int totalMonths = span.GetApproximateMonths();
            int totalYears  = span.GetApproximateYears();

            return(span switch
            {
                { TotalSeconds : <= 1 } => $@"{span:s\.ff} second{(span.Milliseconds != 1 ? "s" : "")}",