/// <summary> /// Determines the relative position compared to the other <see cref="ITemporalPrimitive" /> instance. /// </summary> /// <param name="other">The other instance.</param> /// <returns>The <see cref="RelativePosition" /> of this instance compared to the other.</returns> /// <exception cref="System.ArgumentNullException">The other instance is null.</exception> /// <exception cref="System.ArgumentException">The other instance is not valid.</exception> public RelativePosition RelativePosition(ITemporalPrimitive other) { if (other == null) { throw new ArgumentNullException("other", "The other instance is null."); } if (!other.IsValid) { throw new ArgumentException("The other instance is not valid.", "other"); } if (ReferenceEquals(other, this)) { return(Temporal.RelativePosition.Equals); } if (other is Instant) { return(RelativePosition((Instant)other)); } else if (other is Period) { return(RelativePosition((Period)other)); } else { return(Temporal.RelativePosition.Undefined); } }
/// <summary> /// Computes the distance to the other <see cref="ITemporalPrimitive" /> instance. /// </summary> /// <param name="other">The other instance.</param> /// <returns>The distance to the other <see cref="ITemporalPrimitive" /> instance.</returns> /// <exception cref="System.ArgumentNullException">The other instance is null.</exception> /// <exception cref="System.ArgumentException">The other instance is not valid.</exception> public Duration Distance(ITemporalPrimitive other) { if (other == null) { throw new ArgumentNullException("other", "The other instance is null."); } if (!other.IsValid) { throw new ArgumentException("The other instance is not valid.", "other"); } if (ReferenceEquals(other, this)) { return(Duration.Zero); } if (other is Instant) { return(new Duration(((Instant)other)._ticks - _ticks)); } else if (other is Period) { return(Distance((Period)other)); } else { return(Duration.MinValue); } }
/// <summary> /// Indicates whether this instance and a specified <see cref="ITemporalPrimitive" /> are equal. /// </summary> /// <param name="another">Another <see cref="ITemporalPrimitive" /> to compare to.</param> /// <returns><c>true</c> if <paramref name="another" /> and this instance are the same type and represent the same value; otherwise, <c>false</c>.</returns> public Boolean Equals(ITemporalPrimitive another) { if (ReferenceEquals(another, null)) { return(false); } if (ReferenceEquals(another, this)) { return(true); } return(((another is Instant) && _ticks == ((Instant)another)._ticks) || ((another is Period) && _ticks == ((Period)another).Begin._ticks && _ticks == ((Period)another).End._ticks)); }