예제 #1
0
        public virtual bool Equals(OptionalDateTime another)
        {
            if (another == null)
            {
                return(IsEmpty);
            }

            return(Year == another.Year && Month == another.Month && Day == another.Day);
        }
        public OptionalDateTimeContract(OptionalDateTime dateTime)
        {
            ParamIs.NotNull(() => dateTime);

            Day = dateTime.Day;
            IsEmpty = dateTime.IsEmpty;
            Month = dateTime.Month;
            Year = dateTime.Year;
            Formatted = dateTime.ToString();
        }
예제 #3
0
		private void TestEquals(bool equals, 
			int? firstYear = null, int? firstMonth = null, int? firstDay = null, 
			int? secondYear = null, int? secondMonth = null, int? secondDay = null) {
			
			var first = new OptionalDateTime(firstYear, firstMonth, firstDay);
			var second = new OptionalDateTime(secondYear, secondMonth, secondDay);

			if (equals)
				Assert.AreEqual(first, second, "Dates are equal");
			else
				Assert.AreNotEqual(first, second, "Dates are not equal");

		}
예제 #4
0
		/// <summary>
		/// Tests this date with equality with another.
		/// 
		/// For the purposes of this test, the equality is defined as follows:
		/// - EITHER One or both sides are null OR Empty. Null and Empty are considered equal.
		/// - OR All date components are the same.
		/// 
		/// Note that if the year component is not specified, the date is considered Empty and thus equal to null, 
		/// regardless of the other date components (month and day).
		/// </summary>
		/// <param name="another">Another date object. Can be null.</param>
		/// <returns>True if the dates are considered equal, otherwise false.</returns>
		public virtual bool Equals(OptionalDateTime another) {

			if (another == null)
				return IsEmpty;

			return ((IsEmpty && another.IsEmpty) 
				|| (Year == another.Year && Month == another.Month && Day == another.Day));

		}