using System; namespace Chernobyl.Measures.Time { /// /// The base unit of time in the International System of Units (SI). /// public struct Seconds : ITime, IEquatable, IComparable { /// /// Initializes a new instance of the struct. /// /// The raw value of the measurement as a /// . public Seconds(double value) : this() { Value = value; } /// /// Converts this unit of time to . /// /// This unit of measurement in . public Seconds ToSeconds() { return this; } /// /// Converts from to a floating point /// representation of seconds. /// /// The Seconds to convert to float /// The representative float. public static implicit operator double(Seconds seconds) { return seconds.Value; } /// /// Allows for a double to be explicitly casted to a . /// /// The value to be casted. /// The casted object. public static explicit operator Seconds(double value) { return new Seconds(value); } /// /// Adds two . /// /// The left side of the operation. /// The right side of the operation. /// The result of the operation. public static Seconds operator +(Seconds left, Seconds right) { return new Seconds(left.Value + right.Value); } /// /// Subtracts two . /// /// The left side of the operation. /// The right side of the operation. /// The result of the operation. public static Seconds operator -(Seconds left, Seconds right) { return new Seconds(left.Value - right.Value); } /// /// Multiplies two . /// /// The left side of the operation. /// The right side of the operation. /// The result of the operation. public static Seconds operator *(Seconds left, Seconds right) { return new Seconds(left.Value * right.Value); } /// /// Divides two . /// /// The left side of the operation. /// The right side of the operation. /// The result of the operation. public static Seconds operator /(Seconds left, Seconds right) { return new Seconds(left.Value / right.Value); } /// /// Negates a . /// /// The item to negate. /// The result of the operation. public static Seconds operator -(Seconds item) { return new Seconds(-item.Value); } /// /// Pluses a . /// /// The item to plus. /// The result of the operation. public static Seconds operator +(Seconds item) { return new Seconds(+item.Value); } /// /// Checks if two are equal to each other. /// /// The left side of the operation. /// The right side of the operation. /// True if the two are equal, false if otherwise. public static bool operator ==(Seconds left, Seconds right) { return left.Equals(right); } /// /// Checks if two are equal to each other. /// /// The left side of the operation. /// The right side of the operation. /// True if the two are different, false if otherwise. public static bool operator !=(Seconds left, Seconds right) { return !(left == right); } /// /// Checks if one is less than another. /// /// The left side of the operation. /// The right side of the operation. /// True if the first operand is less than the second, false if /// otherwise. public static bool operator <(Seconds left, Seconds right) { return left.Value < right.Value; } /// /// Checks if one is more than another. /// /// The left side of the operation. /// The right side of the operation. /// True if the first operand is more than the second, false if /// otherwise. public static bool operator >(Seconds left, Seconds right) { return left.Value > right.Value; } /// /// Checks if one is less than or equal to /// another. /// /// The left side of the operation. /// The right side of the operation. /// True if the first operand is less than or equal to the /// second, false if otherwise. public static bool operator <=(Seconds left, Seconds right) { return left.Value <= right.Value; } /// /// Checks if one is more than or equal to /// another. /// /// The left side of the operation. /// The right side of the operation. /// True if the first operand is more than or equal to the /// second, false if otherwise. public static bool operator >=(Seconds left, Seconds right) { return left.Value >= right.Value; } /// /// Gets the hash code of the . /// /// The hash code of the number. public override int GetHashCode() { return Value.GetHashCode(); } /// /// Indicates whether the current object is equal to another object of /// the same type. /// /// An object to compare with this object. /// True if the current object is equal to the /// parameter; otherwise, false. public bool Equals(Seconds other) { return Value == other.Value; } /// /// Checks this for equality with object passed in. /// /// The object to compare to. /// True if the object is equal to this , /// false if otherwise. public override bool Equals(object obj) { return (obj is Seconds && Equals((Seconds)obj)); } /// /// Compares the current object with another object of the same type. /// /// An object to compare with this object. /// A 32-bit signed integer that indicates the relative order /// of the objects being compared. The return value has the following /// meanings: if the value is less than zero then this object is less /// than the parameter. If it is zero then /// this object is equal to . If it is greater /// than zero then this object is greater than . /// public int CompareTo(Seconds other) { return Value.CompareTo(other.Value); } /// /// Returns a that represents this instance. For /// example, 32.0 seconds will be returned as "32.0 s". /// /// A that represents this instance. public override string ToString() { return Value + " s"; } /// /// The raw value of the measurement as a . /// public double Value { get; private set; } } }