Ejemplo n.º 1
0
        /// <summary>
        /// Compares the value of this instance to a specified <see cref="LocalTime"/> value and returns an integer
        /// that indicates whether this instance is earlier than, the same as, or later than the specified
        /// DateTime value.
        /// </summary>
        /// <param name="other">The object to compare to the current instance.</param>
        /// <returns>A signed number indicating the relative values of this instance and the value parameter.</returns>
        public int CompareTo(LocalTime other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (other is null)
            {
                return(1);
            }
            var hourComparison = Hour.CompareTo(other.Hour);

            if (hourComparison != 0)
            {
                return(hourComparison);
            }
            var minuteComparison = Minute.CompareTo(other.Minute);

            if (minuteComparison != 0)
            {
                return(minuteComparison);
            }
            var secondComparison = Second.CompareTo(other.Second);

            if (secondComparison != 0)
            {
                return(secondComparison);
            }
            return(Nanosecond.CompareTo(other.Nanosecond));
        }
Ejemplo n.º 2
0
        public int CompareTo(object obj)
        {
            if (obj is Time time)
            {
                return(CompareTo(time));
            }

            if (obj is TimeSpan timeSpan)
            {
                var hourComp = Hour.CompareTo((uint)timeSpan.Hours);

                if (hourComp != 0)
                {
                    return(hourComp);
                }

                var minComp = Minute.CompareTo((uint)timeSpan.Minutes);

                if (minComp != 0)
                {
                    return(minComp);
                }

                return(Second.CompareTo((uint)timeSpan.Seconds));
            }

            throw new ArgumentException();
        }
        public int CompareTo(object o)
        {
            SimpleDateTime key    = o as SimpleDateTime;
            int            result = Year.CompareTo(key.Year);

            if (result != 0)
            {
                return(result);
            }
            result = Month.CompareTo(key.Month);
            if (result != 0)
            {
                return(result);
            }
            result = Day.CompareTo(key.Day);
            if (result != 0)
            {
                return(result);
            }
            result = Hour.CompareTo(key.Hour);
            if (result != 0)
            {
                return(result);
            }
            result = Min.CompareTo(key.Min);
            return(result);
        }
Ejemplo n.º 4
0
        public int CompareTo(object o)
        {
            KeyStruct key    = o as KeyStruct;
            int       result = Year.CompareTo(key.Year);

            if (result != 0)
            {
                return(result);
            }
            result = Month.CompareTo(key.Month);
            if (result != 0)
            {
                return(result);
            }
            result = Day.CompareTo(key.Day);
            if (result != 0)
            {
                return(result);
            }
            result = Hour.CompareTo(key.Hour);
            if (result != 0)
            {
                return(result);
            }
            result = Min.CompareTo(key.Min);
            if (result != 0)
            {
                return(result);
            }
            result = ID.CompareTo(key.ID);
            return(result);
        }
Ejemplo n.º 5
0
        private int CompareTo(IGameDateTime gameDateTime)
        {
            if (gameDateTime == null)
            {
                throw new NullReferenceException("Game date time can not be null.");
            }

            if (Year != gameDateTime.Year)
            {
                return(Year.CompareTo(gameDateTime.Year));
            }
            else if (Month != gameDateTime.Month)
            {
                return(Month.CompareTo(gameDateTime.Month));
            }
            else if (Day != gameDateTime.Day)
            {
                return(Day.CompareTo(gameDateTime.Day));
            }
            else if (Hour != gameDateTime.Hour)
            {
                return(Hour.CompareTo(gameDateTime.Hour));
            }
            else if (Minute != gameDateTime.Minute)
            {
                return(Minute.CompareTo(gameDateTime.Minute));
            }

            return(0);
        }
Ejemplo n.º 6
0
        public void Should_compare_with_null_instance(double value)
        {
            var instance = new Hour(value);

            Assert.IsFalse(instance.Equals(null), "Equals");
            Assert.AreEqual(1, instance.CompareTo(null), "CompareTo");
        }
Ejemplo n.º 7
0
        public void Should_compare_with_another_type_of_instance(double value)
        {
            var    instance1 = new Hour(value);
            object instance2 = value;

            Assert.IsFalse(instance1.Equals(instance2), "Equals");
            Assert.Throws <ArgumentException>(() => instance1.CompareTo(instance2), "CompareTo");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Compares the current instance with another object of the same type and returns an integer that
        /// indicates whether the current instance precedes, follows, or occurs in the same position in the
        /// sort order as the other object.
        /// </summary>
        /// <param name="other">The object to compare with this instance.</param>
        /// <returns>A value that indicates the relative order of the objects being compared.</returns>
        public int CompareTo(TimeSlotRow other)
        {
            if (other == null)
            {
                return(1);
            }

            var hourComparison = Hour.CompareTo(other.Hour);

            if (hourComparison != 0)
            {
                return(hourComparison);
            }

            var mondayComparison = Monday.CompareTo(other.Monday);

            if (mondayComparison != 0)
            {
                return(mondayComparison);
            }

            var tuesdayComparison = Tuesday.CompareTo(other.Tuesday);

            if (tuesdayComparison != 0)
            {
                return(tuesdayComparison);
            }

            var wednesdayComparison = Wednesday.CompareTo(other.Wednesday);

            if (wednesdayComparison != 0)
            {
                return(wednesdayComparison);
            }

            var thursdayComparison = Thursday.CompareTo(other.Thursday);

            if (thursdayComparison != 0)
            {
                return(thursdayComparison);
            }

            var fridayComparison = Friday.CompareTo(other.Friday);

            if (fridayComparison != 0)
            {
                return(fridayComparison);
            }

            var saturdayComparison = Saturday.CompareTo(other.Saturday);

            if (saturdayComparison != 0)
            {
                return(saturdayComparison);
            }

            return(Sunday.CompareTo(other.Sunday));
        }
Ejemplo n.º 9
0
        public void Should_compare_with_smaller_value(double baseValue, double smallerValue)
        {
            var baseInstance    = new Hour(baseValue);
            var smallerInstance = new Hour(smallerValue);

            Assert.IsFalse(baseInstance.Equals(smallerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)smallerInstance), "Equals object");

            Assert.IsFalse(baseInstance == smallerInstance, "==");
            Assert.IsTrue(baseInstance != smallerInstance, "!=");

            Assert.AreEqual(+1, baseInstance.CompareTo(smallerInstance), "CompareTo");
            Assert.AreEqual(+1, baseInstance.CompareTo((object)smallerInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < smallerInstance, "<");
            Assert.IsTrue(baseInstance > smallerInstance, ">");

            Assert.IsFalse(baseInstance <= smallerInstance, "<=");
            Assert.IsTrue(baseInstance >= smallerInstance, ">=");
        }
Ejemplo n.º 10
0
        public void Should_compare_with_same_value(double value)
        {
            var baseInstance  = new Hour(value);
            var otherInstance = new Hour(value);

            Assert.IsTrue(baseInstance.Equals(otherInstance), "Equals");
            Assert.IsTrue(baseInstance.Equals((object)otherInstance), "Equals object");

            Assert.IsTrue(baseInstance == otherInstance, "==");
            Assert.IsFalse(baseInstance != otherInstance, "!=");

            Assert.AreEqual(0, baseInstance.CompareTo(otherInstance), "CompareTo");
            Assert.AreEqual(0, baseInstance.CompareTo((object)otherInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < otherInstance, "<");
            Assert.IsFalse(baseInstance > otherInstance, ">");

            Assert.IsTrue(baseInstance <= otherInstance, "<=");
            Assert.IsTrue(baseInstance >= otherInstance, ">=");
        }
Ejemplo n.º 11
0
 public int CompareTo(object obj)
 {
     if (obj is Time)
     {
         if (Hour.Equals(((Time)obj).Hour))
         {
             return(Minute.CompareTo(((Time)obj).Minute));
         }
     }
     return(Hour.CompareTo(obj));
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Compares two instances of this object.
        /// </summary>
        /// <param name="HourMin">An object to compare with.</param>
        public Int32 CompareTo(HourMin HourMin)
        {
            var c = Hour.CompareTo(HourMin.Hour);

            if (c == 0)
            {
                c = Minute.CompareTo(HourMin.Minute);
            }

            return(c);
        }
Ejemplo n.º 13
0
        public void Should_compare_with_bigger_value(double baseValue, double biggerValue)
        {
            var baseInstance   = new Hour(baseValue);
            var biggerInstance = new Hour(biggerValue);

            Assert.IsFalse(baseInstance.Equals(biggerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)biggerInstance), "Equals object");

            Assert.IsFalse(baseInstance == biggerInstance, "==");
            Assert.IsTrue(baseInstance != biggerInstance, "!=");

            Assert.AreEqual(-1, baseInstance.CompareTo(biggerInstance), "CompareTo");
            Assert.AreEqual(-1, baseInstance.CompareTo((object)biggerInstance), "CompareTo object");

            Assert.IsTrue(baseInstance < biggerInstance, "<");
            Assert.IsFalse(baseInstance > biggerInstance, ">");

            Assert.IsTrue(baseInstance <= biggerInstance, "<=");
            Assert.IsFalse(baseInstance >= biggerInstance, ">=");
        }
Ejemplo n.º 14
0
        public int CompareTo(Time other)
        {
            var result = Hour.CompareTo(other.Hour);

            if (result == 0)
            {
                result = Minute.CompareTo(other.Minute);
            }
            if (result == 0)
            {
                result = Second.CompareTo(other.Second);
            }
            return(result);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Compares the value of this instance to a specified <see cref="LocalDateTime"/> value and returns an integer
        /// that indicates whether this instance is earlier than, the same as, or later than the specified
        /// DateTime value.
        /// </summary>
        /// <param name="other">The object to compare to the current instance.</param>
        /// <returns>A signed number indicating the relative values of this instance and the value parameter.</returns>
        public int CompareTo(LocalDateTime other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (other is null)
            {
                return(1);
            }
            var yearComparison = Year.CompareTo(other.Year);

            if (yearComparison != 0)
            {
                return(yearComparison);
            }
            var monthComparison = Month.CompareTo(other.Month);

            if (monthComparison != 0)
            {
                return(monthComparison);
            }
            var dayComparison = Day.CompareTo(other.Day);

            if (dayComparison != 0)
            {
                return(dayComparison);
            }
            var hourComparison = Hour.CompareTo(other.Hour);

            if (hourComparison != 0)
            {
                return(hourComparison);
            }
            var minuteComparison = Minute.CompareTo(other.Minute);

            if (minuteComparison != 0)
            {
                return(minuteComparison);
            }
            var secondComparison = Second.CompareTo(other.Second);

            if (secondComparison != 0)
            {
                return(secondComparison);
            }
            return(Nanosecond.CompareTo(other.Nanosecond));
        }
Ejemplo n.º 16
0
        public int CompareTo(TimeOfDay?other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            if (Hour == other.Hour)
            {
                return(Minute.CompareTo(other.Minute));
            }

            return(Hour.CompareTo(other.Hour));
        }
Ejemplo n.º 17
0
        public int CompareTo(Time other)
        {
            int hourComparation = Hour.CompareTo(other.Hour);

            if (hourComparation == 0)
            {
                int minuteComparation = Minute.CompareTo(other.Minute);
                if (minuteComparation == 0)
                {
                    return(Second.CompareTo(other.Second));
                }

                return(minuteComparation);
            }

            return(hourComparation);
        }
Ejemplo n.º 18
0
        public int CompareTo(Time other)
        {
            var hourComp = Hour.CompareTo(other.Hour);

            if (hourComp != 0)
            {
                return(hourComp);
            }

            var minComp = Minute.CompareTo(other.Minute);

            if (minComp != 0)
            {
                return(minComp);
            }

            return(Second.CompareTo(other.Second));
        }
Ejemplo n.º 19
0
        }                                                     // обычно ToString возвращает российский формат

        public int CompareTo(object ob)
        {
            Date comp = (Date)ob;

            int year   = Year.CompareTo(comp.Year);
            int month  = Month.CompareTo(comp.Month);
            int day    = Day.CompareTo(comp.Day);
            int hour   = Hour.CompareTo(comp.Hour);
            int minute = Minute.CompareTo(comp.Minute);
            int second = Second.CompareTo(comp.Second);

            if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0)
            {
                return(0);
            }

            if (year != 0)
            {
                return(year);
            }
            if (month != 0)
            {
                return(month);
            }
            if (day != 0)
            {
                return(day);
            }
            if (hour != 0)
            {
                return(hour);
            }
            if (minute != 0)
            {
                return(minute);
            }
            if (second != 0)
            {
                return(second);
            }

            return(1);
        }
Ejemplo n.º 20
0
        public int CompareTo(GuardLog otherLog)
        {
            int result = Year.CompareTo(otherLog.Year);

            if (result == 0)
            {
                result = Month.CompareTo(otherLog.Month);
            }
            if (result == 0)
            {
                result = Day.CompareTo(otherLog.Day);
            }
            if (result == 0)
            {
                result = Hour.CompareTo(otherLog.Hour);
            }
            if (result == 0)
            {
                result = Minute.CompareTo(otherLog.Minute);
            }

            return(result);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Compares the current instance with another object of the same type and returns an integer that
        /// indicates whether the current instance precedes, follows, or occurs in the same position in the
        /// sort order as the other object.
        /// </summary>
        /// <param name="other">The object to compare with this instance.</param>
        /// <returns>A value that indicates the relative order of the objects being compared.</returns>
        public int CompareTo(TimeSlot other)
        {
            if (other == null)
            {
                return(1);
            }

            var dayComparison = CompareDay(other.Day);

            if (dayComparison != 0)
            {
                return(dayComparison);
            }

            var hourComparison = Hour.CompareTo(other.Hour);

            if (hourComparison != 0)
            {
                return(hourComparison);
            }

            return(Active.CompareTo(other.Active));
        }
Ejemplo n.º 22
0
        public int CompareTo(Time time)
        {
            int result;

            result = Year.CompareTo(time.Year);
            if (result != 0)
            {
                return(result);
            }

            result = Month.CompareTo(time.Month);
            if (result != 0)
            {
                return(result);
            }

            result = Day.CompareTo(time.Day);
            if (result != 0)
            {
                return(result);
            }

            result = Hour.CompareTo(time.Hour);
            if (result != 0)
            {
                return(result);
            }

            result = Minute.CompareTo(time.Minute);
            if (result != 0)
            {
                return(result);
            }

            result = Second.CompareTo(time.Second);
            return(result);
        }