//******************************************************************************************************
// Time.cs - Gbtc
//
// Copyright © 2012, 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:
// ----------------------------------------------------------------------------------------------------
// 01/25/2008 - J. Ritchie Carroll
// Initial version of source generated.
// 09/11/2008 - J. Ritchie Carroll
// Converted to C#.
// 08/10/2009 - Josh L. Patterson
// Edited Comments.
// 09/14/2009 - Stephen C. Wills
// Added new header and license agreement.
// 12/14/2012 - Starlynn Danyelle Gilliam
// Modified Header.
// 10/03/2017 - J. Ritchie Carroll
// Added units enumeration with associated Convert method.
//
//******************************************************************************************************
#region [ Contributor License Agreements ]
/**************************************************************************\
Copyright © 2009 - J. Ritchie Carroll
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\**************************************************************************/
#endregion
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;
namespace GSF.Units
{
#region [ Enumerations ]
///
/// Represents the units available for a value.
///
public enum TimeUnit
{
///
/// Second time units.
///
Seconds,
///
/// Minute time units.
///
Minutes,
///
/// Hour time units.
///
Hours,
///
/// Day time units.
///
Days,
///
/// Week time units.
///
Weeks,
///
/// Tick time units, 100-nanosecond intervals since 1/1/0001.
///
Ticks,
///
/// Atomic time units.
///
AtomicUnitsOfTime,
///
/// Planck time units.
///
PlanckTime,
///
/// Ke time units, traditional Chinese unit of decimal time.
///
Ke
}
#endregion
///
/// Represents a time measurement, in seconds, as a double-precision floating-point number.
///
///
/// This class behaves just like a representing a time in seconds; it is implicitly
/// castable to and from a and therefore can be generally used "as" a double, but it
/// has the advantage of handling conversions to and from other time representations, specifically
/// minutes, hours, days, weeks, atomic units of time, Planck time and ke. Metric conversions are handled
/// simply by applying the needed conversion factor, for example:
///
/// Convert time in nanoseconds to seconds:
///
/// public Time GetSeconds(double nanoseconds)
/// {
/// return nanoseconds * SI.Nano;
/// }
///
/// Convert time in seconds to milliseconds:
///
/// public double GetMilliseconds(Time seconds)
/// {
/// return time / SI.Milli;
/// }
///
/// This example converts minutes to hours:
///
/// public double GetHours(double minutes)
/// {
/// return Time.FromMinutes(minutes).ToHours();
/// }
///
///
///
/// Note that the method will convert the value, in seconds,
/// into a textual representation of years, days, hours, minutes and seconds using the static function
/// .
///
///
// ReSharper disable RedundantNameQualifier
[Serializable]
public struct Time : IComparable, IFormattable, IConvertible, IComparable