public void DurationComparerTest()
        {
            DateTime  now   = ClockProxy.Clock.Now;
            TimeRange left  = new TimeRange(now, now.AddDays(1));
            TimeRange right = new TimeRange(now, now.AddDays(2));

            // base
            Assert.AreEqual(0, left.CompareTo(left, TimePeriodDurationComparer.Comparer));
            Assert.AreEqual(-1, left.CompareTo(right, TimePeriodDurationComparer.Comparer));
            Assert.AreEqual(1, right.CompareTo(left, TimePeriodDurationComparer.Comparer));

            // revers
            Assert.AreEqual(0, left.CompareTo(left, TimePeriodDurationComparer.ReverseComparer));
            Assert.AreEqual(1, left.CompareTo(right, TimePeriodDurationComparer.ReverseComparer));
            Assert.AreEqual(-1, right.CompareTo(left, TimePeriodDurationComparer.ReverseComparer));
        } // DurationComparerTest
Beispiel #2
0
            public int Compare(TimeRange <T> x, TimeRange <T> y)
            {
                // Want to show more recent jobs first, so reverse the default order.

                if (x == null)
                {
                    return(y == null ? 0 : 1);
                }
                return(y == null
                    ? -1
                    : -1 * x.CompareTo(y));
            }
Beispiel #3
0
        public void Should_return_range_for_today()
        {
            // Given
            var startDate = DateTime.UtcNow.ToEstTime().ChangeTime(16, 0, 0, 0);
            var endDate   = startDate.EndOfDay();

            TimeRange mainDateRange     = new TimeRange(startDate.StartOfDay(), endDate);
            TimeRange alignedDateRange  = new TimeRange(startDate.GetPreviousTradingDay(), endDate.EndOfDay());
            TimeRange extendedDateRnage = new TimeRange(startDate.GetPreviousTradingDay().StartOfDay(), endDate);

            // When
            var       dateRange = MarketCalendar.CalculateTradingTimeRange(DateRange.Today);
            TimeRange arketCalendarMainDateRange     = dateRange.TimeRange as TimeRange;
            TimeRange arketCalendarAlignedDateRange  = dateRange.AlignedTimeRange as TimeRange;
            TimeRange arketCalendarExtendedDateRnage = dateRange.ExtendedTimeRange as TimeRange;

            // Then
            Assert.IsTrue(arketCalendarMainDateRange != null && arketCalendarMainDateRange.CompareTo(mainDateRange) == 0);
            Assert.IsTrue(arketCalendarAlignedDateRange != null && arketCalendarAlignedDateRange.CompareTo(arketCalendarAlignedDateRange) == 0);
            Assert.IsTrue(arketCalendarExtendedDateRnage != null && arketCalendarExtendedDateRnage.CompareTo(arketCalendarExtendedDateRnage) == 0);
        }