Esempio n. 1
0
        public void CompareTo()
        {
            LocalTime time1 = new LocalTime(10, 30, 45);
            LocalTime time2 = new LocalTime(10, 30, 45);
            LocalTime time3 = new LocalTime(10, 30, 50);

            Assert.That(time1.CompareTo(time2), Is.EqualTo(0));
            Assert.That(time1.CompareTo(time3), Is.LessThan(0));
            Assert.That(time3.CompareTo(time2), Is.GreaterThan(0));
        }
        public void ShouldReportLargerOnCompareToNull()
        {
            var time1 = new LocalTime(0, 0, 0, 0);

            var comp = time1.CompareTo(null);

            comp.Should().BeGreaterThan(0);
        }
        public void ShouldThrowOnCompareToOtherType()
        {
            var time1 = new LocalTime(0, 0, 0, 0);

            var ex = Record.Exception(() => time1.CompareTo(new DateTime(1947, 12, 17)));

            ex.Should().NotBeNull().And.BeOfType <ArgumentException>();
        }
        public void ShouldReportSmallerOnCompareTo()
        {
            var time1 = new LocalTime(0, 59, 59, 999999999);
            var time2 = new LocalTime(23, 59, 59, 999999999);

            var comp = time1.CompareTo(time2);

            comp.Should().BeLessThan(0);
        }
        public void ShouldReportEqualOnCompareTo()
        {
            var time1 = new LocalTime(23, 59, 59, 999999999);
            var time2 = new LocalTime(23, 59, 59, 999999999);

            var comp = time1.CompareTo(time2);

            comp.Should().Be(0);
        }
        public void ShouldReportLargerOnCompareTo()
        {
            var time1 = new LocalTime(23, 59, 59, 999999999);
            var time2 = new LocalTime(23, 59, 59, 0);

            var comp = time1.CompareTo(time2);

            comp.Should().BeGreaterThan(0);
        }
Esempio n. 7
0
        /// <summary>
        /// Test if the specified time falls within the shift
        /// </summary>
        /// <param name="time">Local time</param>
        /// <returns>True if this time is in the shift</returns>
        public bool IsInShift(LocalTime time)
        {
            bool answer = false;

            LocalTime start = StartTime;
            LocalTime end   = GetEnd();

            int onStart = time.CompareTo(start);
            int onEnd   = time.CompareTo(end);

            int timeSecond = SecondOfDay(time);

            if (start.CompareTo(end) < 0)
            {
                // shift did not cross midnight
                if (onStart >= 0 && onEnd <= 0)
                {
                    answer = true;
                }
            }
            else
            {
                // shift crossed midnight, check before and after midnight
                if (timeSecond <= SecondOfDay(end))
                {
                    // after midnight
                    answer = true;
                }
                else
                {
                    // before midnight
                    if (timeSecond >= SecondOfDay(start))
                    {
                        answer = true;
                    }
                }
            }
            return(answer);
        }
        /**
         * <p>find nearest next time</p>
         * @param startTime is LocalTime representation of start time
         * @param actualNode is int representation of actual node
         * @param i  is int representation of cycle from parent calling method
         * @param timeDepartures is array of time departures between all two nodes in graph
         * @return next nearest LocalTime to start time
         */
        private LocalTime findImmediateTime(LocalTime startTime, int actualNode, int i, LocalTime[,] timeDepartures)
        {
            int       k        = 0;
            LocalTime nextTime = data[actualNode, i].times[k];

            //find in list of departures in day in actualNode nearest actualTIme
            while (startTime.CompareTo(nextTime) > 0 && !(startTime.Equals(nextTime)))
            {
                k++;
                //if occured new day, start at begin in list and time departure will set to 00:00
                if (k >= data[actualNode, i].times.Length)
                {
                    k = 0;
                    //timeDepartures[actualNode][i] = LocalTime.parse("00:00");
                    startTime = parseTime("00:00");
                    newDay    = true;
                }
                nextTime = data[actualNode, i].times[k];
            }

            return(nextTime);
        }
        public void CompareTo()
        {
            LocalTime time1 = new LocalTime(10, 30, 45);
            LocalTime time2 = new LocalTime(10, 30, 45);
            LocalTime time3 = new LocalTime(10, 30, 50);

            Assert.That(time1.CompareTo(time2), Is.EqualTo(0));
            Assert.That(time1.CompareTo(time3), Is.LessThan(0));
            Assert.That(time3.CompareTo(time2), Is.GreaterThan(0));
        }