//******************************************************************************************************
// TimeSpanExtensions.cs - Gbtc
//
// Copyright © 2013, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
// not use this file except in compliance with the License. You may obtain a copy of the License at:
//
// http://www.opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// -----------------------------------------------------------------------------------------------------
// 12/14/2008 - F. Russell Robertson
// Generated original version of source code.
// 05/30/2008 - J. Ritchie Carroll
// Updated to use existing elapsed time string function of GSF.Units.Time.
//
//*******************************************************************************************************
using System;
using GSF.Units;
namespace GSF
{
///
/// Extends the TimeSpan Class
///
public static class TimeSpanExtensions
{
///
/// Converts the value into a textual representation of years, days, hours,
/// minutes and seconds with the specified number of fractional digits.
///
/// The to process.
/// Number of fractional digits to display for seconds. Defaults to 2.
/// Minimum sub-second resolution to display. Defaults to .
/// Set second precision to -1 to suppress seconds display.
///
/// The string representation of the value of this , consisting of the number of
/// years, days, hours, minutes and seconds represented by this value.
///
///
/// DateTime g_start = DateTime.UtcNow;
/// DateTime EndTime = DateTime.UtcNow;
/// TimeSpan duration = EndTime.Subtract(g_start);
/// Console.WriteLine("Elapsed Time = " + duration.ToElapsedTimeString());
///
///
/// is not less than or equal to or
/// is not defined in array.
///
public static string ToElapsedTimeString(this TimeSpan value, int secondPrecision = 2, double minimumSubSecondResolution = SI.Milli)
{
return Time.ToElapsedTimeString(value.TotalSeconds, secondPrecision, null, minimumSubSecondResolution);
}
}
}