/// <summary> /// Compares this object to another <see cref="SmartDate"/> /// for equality. /// </summary> /// <param name="obj">Object to compare for equality.</param> public override bool Equals(object obj) { if (obj is SmartDate) { SmartDate tmp = (SmartDate)obj; if (this.IsEmpty && tmp.IsEmpty) { return(true); } else { return(this.Date.Equals(tmp.Date)); } } else if (obj is DateTime) { return(this.Date.Equals((DateTime)obj)); } else if (obj is string) { return(this.CompareTo(obj.ToString()) == 0); } else { return(false); } }
/// <summary> /// Compares one SmartDate to another. /// </summary> /// <remarks> /// This method works the same as the DateTime.CompareTo method /// on the Date datetype, with the exception that it /// understands the concept of empty date values. /// </remarks> /// <param name="value">The date to which we are being compared.</param> /// <returns>A value indicating if the comparison date is less than, equal to or greater than this date.</returns> public int CompareTo(SmartDate value) { if (this.IsEmpty && value.IsEmpty) { return(0); } else { return(_date.CompareTo(value.Date)); } }
/// <summary> /// Converts a string value into a SmartDate. /// </summary> /// <param name="value">String containing the date value.</param> /// <param name="emptyValue">Indicates whether an empty date is the min or max date value.</param> /// <param name="result">The resulting SmartDate value if the parse was successful.</param> /// <returns>A value indicating if the parse was successful.</returns> public static bool TryParse(string value, EmptyValue emptyValue, ref SmartDate result) { System.DateTime dateResult = DateTime.MinValue; if (TryStringToDate(value, emptyValue, ref dateResult)) { result = new SmartDate(dateResult, emptyValue); return(true); } else { return(false); } }
/// <summary> /// Converts a string value into a SmartDate. /// </summary> /// <param name="value">String containing the date value.</param> /// <param name="result">The resulting SmartDate value if the parse was successful.</param> /// <returns>A value indicating if the parse was successful.</returns> public static bool TryParse(string value, ref SmartDate result) { return(TryParse(value, EmptyValue.MinDate, ref result)); }