Exemplo n.º 1
0
        public void One_year_tick_interval()
        {
            var tickInterval = GetFirstTickIntervalWithGreaterDuration(Duration.Zero.AddMonths(8));

            tickInterval.ShouldNotBeNull();

            var d1 = ExactDateInfo.AnnoDomini(100, 1, 1, 0);
            var d2 = ExactDateInfo.AnnoDomini(102, 1, 1, 0);

            var ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(d1);
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(101, 1, 1, 0));
            ticks[2].Date.ShouldBe(d2);

            d1 = ExactDateInfo.AnnoDomini(100, 3, 3, 5);
            d2 = ExactDateInfo.AnnoDomini(104, 8, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(4);

            ticks[0].Date.ShouldBe(ExactDateInfo.AnnoDomini(101, 1, 1, 0));
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(102, 1, 1, 0));
            ticks[2].Date.ShouldBe(ExactDateInfo.AnnoDomini(103, 1, 1, 0));
            ticks[3].Date.ShouldBe(ExactDateInfo.AnnoDomini(104, 1, 1, 0));

            d1 = ExactDateInfo.BeforeChrist(100, 3, 3, 5);
            d2 = ExactDateInfo.BeforeChrist(97, 8, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(ExactDateInfo.BeforeChrist(99, 1, 1, 0));
            ticks[1].Date.ShouldBe(ExactDateInfo.BeforeChrist(98, 1, 1, 0));
            ticks[2].Date.ShouldBe(ExactDateInfo.BeforeChrist(97, 1, 1, 0));

            d1 = ExactDateInfo.BeforeChrist(2, 3, 3, 5);
            d2 = ExactDateInfo.AnnoDomini(2, 8, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(ExactDateInfo.BeforeChrist(1, 1, 1, 0));
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(1, 1, 1, 0));
            ticks[2].Date.ShouldBe(ExactDateInfo.AnnoDomini(2, 1, 1, 0));

            d1 = ExactDateInfo.AnnoDomini(1, 3, 3, 5);
            d2 = ExactDateInfo.AnnoDomini(2, 8, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(1);

            ticks[0].Date.ShouldBe(ExactDateInfo.AnnoDomini(2, 1, 1, 0));
        }
        public async Task Get_events_from_time_range_with_only_end_in_range()
        {
            // Act

            var now = DateTime.Now;

            var rangeEnd = new ExactDateInfo(
                Era.AnnoDomini,
                now.Year + 1,
                1,
                1,
                1
                );

            var eventsInTimeRange = await _fixture.EventsRepo.GetEventsAsync(
                InRange(
                    ExactDateInfo.AnnoDomini(2020, 2, 1, 0),
                    rangeEnd
                    )
                );

            // Assert

            eventsInTimeRange.ShouldNotBeNull();
            eventsInTimeRange.Count.ShouldBe(2);

            eventsInTimeRange.ShouldContain(e => e.Description == "C");
            eventsInTimeRange.ShouldContain(e => e.Description == "D");
        }
Exemplo n.º 3
0
        public void One_hour_tick_interval()
        {
            var tickInterval = GetFirstTickIntervalWithGreaterDuration(Duration.Zero);

            tickInterval.ShouldNotBeNull();

            var d1 = ExactDateInfo.AnnoDomini(100, 2, 3, 12);
            var d2 = ExactDateInfo.AnnoDomini(100, 2, 3, 14);

            var ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(d1);
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(100, 2, 3, 13));
            ticks[2].Date.ShouldBe(d2);

            d1 = ExactDateInfo.BeforeChrist(100, 2, 3, 12);
            d2 = ExactDateInfo.BeforeChrist(100, 2, 3, 14);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(d1);
            ticks[1].Date.ShouldBe(ExactDateInfo.BeforeChrist(100, 2, 3, 13));
            ticks[2].Date.ShouldBe(d2);
        }
Exemplo n.º 4
0
        public void Several_years_tick_interval(long years)
        {
            var tickInterval = GetFirstTickIntervalWithGreaterDuration(Duration.Zero.AddYears(years).AddMonths(-1));

            tickInterval.ShouldNotBeNull();

            var d1 = ExactDateInfo.AnnoDomini(years, 1, 1, 0);
            var d2 = ExactDateInfo.AnnoDomini(3 * years, 1, 1, 0);

            var ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(d1);
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(years * 2, 1, 1, 0));
            ticks[2].Date.ShouldBe(d2);

            d1 = ExactDateInfo.AnnoDomini(years, 3, 3, 5);
            d2 = ExactDateInfo.AnnoDomini(years * 4, 8, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(ExactDateInfo.AnnoDomini(years * 2, 1, 1, 0));
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(years * 3, 1, 1, 0));
            ticks[2].Date.ShouldBe(ExactDateInfo.AnnoDomini(years * 4, 1, 1, 0));

            d1 = ExactDateInfo.BeforeChrist(years * 4, 3, 3, 5);
            d2 = ExactDateInfo.BeforeChrist(years * 1, 8, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(ExactDateInfo.BeforeChrist(years * 3, 1, 1, 0));
            ticks[1].Date.ShouldBe(ExactDateInfo.BeforeChrist(years * 2, 1, 1, 0));
            ticks[2].Date.ShouldBe(ExactDateInfo.BeforeChrist(years * 1, 1, 1, 0));

            d1 = ExactDateInfo.BeforeChrist(years * 2, 3, 3, 5);
            d2 = ExactDateInfo.AnnoDomini(years * 1, 8, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(ExactDateInfo.BeforeChrist(years * 1, 1, 1, 0));
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(1, 1, 1, 0));
            ticks[2].Date.ShouldBe(ExactDateInfo.AnnoDomini(years * 1, 1, 1, 0));
        }
Exemplo n.º 5
0
        public void Scaling_down_one_month()
        {
            var timeRange = new TimeRange(
                ExactDateInfo.AnnoDomini(100, 1, 1, 0),
                ExactDateInfo.AnnoDomini(100, 7, 1, 0)
                );

            var scaledTimeRange = timeRange.ScaleDown(Duration.Zero.AddDays(20));

            scaledTimeRange.ShouldNotBeNull();

            scaledTimeRange.Start.ShouldBe(timeRange.Middle - Duration.Zero.AddDays(3));
            scaledTimeRange.End.ShouldBe(timeRange.Middle + Duration.Zero.AddDays(3));
            scaledTimeRange.Middle.ShouldBe(timeRange.Middle);
        }
Exemplo n.º 6
0
        public void Scaling_down_twelve_hours()
        {
            var timeRange = new TimeRange(
                ExactDateInfo.AnnoDomini(100, 1, 1, 0),
                ExactDateInfo.AnnoDomini(100, 1, 2, 0)
                );

            var scaledTimeRange = timeRange.ScaleDown(Duration.Zero.AddHours(4));

            scaledTimeRange.ShouldNotBeNull();

            scaledTimeRange.Start.ShouldBe(timeRange.Middle - Duration.Zero.AddHours(1));
            scaledTimeRange.End.ShouldBe(timeRange.Middle + Duration.Zero.AddHours(1));
            scaledTimeRange.Middle.ShouldBe(timeRange.Middle);
        }
Exemplo n.º 7
0
        public void Scaling_down_one_hour_should_do_nothing()
        {
            var timeRange = new TimeRange(
                ExactDateInfo.AnnoDomini(100, 1, 1, 0),
                ExactDateInfo.AnnoDomini(100, 1, 1, 10)
                );

            var scaledTimeRange = timeRange.ScaleDown(Duration.Zero.AddHours(1));

            scaledTimeRange.ShouldNotBeNull();

            scaledTimeRange.Start.ShouldBe(timeRange.Start);
            scaledTimeRange.End.ShouldBe(timeRange.End);
            scaledTimeRange.Middle.ShouldBe(timeRange.Middle);
        }
Exemplo n.º 8
0
        public void Scaling_up_hours()
        {
            var timeRange = new TimeRange(
                ExactDateInfo.AnnoDomini(100, 1, 1, 0),
                ExactDateInfo.AnnoDomini(100, 1, 1, 10)
                );

            var scaledTimeRange = timeRange.ScaleUp(Duration.Zero.AddHours(1));

            scaledTimeRange.ShouldNotBeNull();

            scaledTimeRange.Start.ShouldBe(timeRange.Start - Duration.Zero.AddHours(55));
            scaledTimeRange.End.ShouldBe(timeRange.End + Duration.Zero.AddHours(55));
            scaledTimeRange.Middle.ShouldBe(timeRange.Middle);
        }
Exemplo n.º 9
0
        public void Scaling_up_one_year()
        {
            var timeRange = new TimeRange(
                ExactDateInfo.AnnoDomini(100, 1, 1, 0),
                ExactDateInfo.AnnoDomini(106, 1, 1, 0)
                );

            var scaledTimeRange = timeRange.ScaleUp(Duration.Zero.AddMonths(10));

            scaledTimeRange.ShouldNotBeNull();

            scaledTimeRange.Start.ShouldBe(timeRange.Start - Duration.Zero.AddYears(27));
            scaledTimeRange.End.ShouldBe(timeRange.End + Duration.Zero.AddYears(27));
            scaledTimeRange.Middle.ShouldBe(timeRange.Middle);
        }
        public async Task Get_events_from_time_range_with_no_events()
        {
            // Act

            var eventsInTimeRange = await _fixture.EventsRepo.GetEventsAsync(
                InRange(
                    ExactDateInfo.AnnoDomini(3000, 1, 1, 0),
                    ExactDateInfo.AnnoDomini(4000, 1, 1, 0)
                    )
                );

            // Assert

            eventsInTimeRange.ShouldNotBeNull();
            eventsInTimeRange.ShouldBeEmpty();
        }
        public async Task Get_events_from_time_range_with_only_start_in_range()
        {
            // Act

            var eventsInTimeRange = await _fixture.EventsRepo.GetEventsAsync(
                InRange(
                    ExactDateInfo.BeforeChrist(20, 1, 1, 0),
                    ExactDateInfo.AnnoDomini(1, 1, 1, 0)
                    )
                );

            // Assert

            eventsInTimeRange.ShouldNotBeNull();
            eventsInTimeRange.Count.ShouldBe(2);

            eventsInTimeRange.ShouldContain(e => e.Description == "A");
            eventsInTimeRange.ShouldContain(e => e.Description == "B");
        }
        public async Task Revert_specification()
        {
            // Act

            var eventsInTimeRange = await _fixture.EventsRepo.GetEventsAsync(
                Not(
                    InRange(
                        ExactDateInfo.BeforeChrist(20, 1, 1, 0),
                        ExactDateInfo.AnnoDomini(1, 1, 1, 0)
                        )
                    )
                );

            // Assert

            eventsInTimeRange.ShouldNotBeNull();
            eventsInTimeRange.Count.ShouldBe(3);

            eventsInTimeRange.ShouldContain(e => e.Description == "C");
            eventsInTimeRange.ShouldContain(e => e.Description == "D");
            eventsInTimeRange.ShouldContain(e => e.Description == "E");
        }
Exemplo n.º 13
0
        public void One_month_tick_interval()
        {
            var tickInterval = GetFirstTickIntervalWithGreaterDuration(Duration.Zero.AddDays(20));

            tickInterval.ShouldNotBeNull();

            var d1 = ExactDateInfo.AnnoDomini(100, 2, 1, 0);
            var d2 = ExactDateInfo.AnnoDomini(100, 5, 1, 0);

            var ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(4);

            ticks[0].Date.ShouldBe(d1);
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(100, 3, 1, 0));
            ticks[2].Date.ShouldBe(ExactDateInfo.AnnoDomini(100, 4, 1, 0));
            ticks[3].Date.ShouldBe(d2);

            d1 = ExactDateInfo.AnnoDomini(100, 3, 3, 5);
            d2 = ExactDateInfo.AnnoDomini(100, 5, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(2);

            ticks[0].Date.ShouldBe(ExactDateInfo.AnnoDomini(100, 4, 1, 0));
            ticks[1].Date.ShouldBe(ExactDateInfo.AnnoDomini(100, 5, 1, 0));

            d1 = ExactDateInfo.BeforeChrist(100, 11, 3, 5);
            d2 = ExactDateInfo.BeforeChrist(99, 2, 5, 17);

            ticks = tickInterval.GetTicksBetween(d1, d2).ToArray();

            ticks.Length.ShouldBe(3);

            ticks[0].Date.ShouldBe(ExactDateInfo.BeforeChrist(100, 12, 1, 0));
            ticks[1].Date.ShouldBe(ExactDateInfo.BeforeChrist(99, 1, 1, 0));
            ticks[2].Date.ShouldBe(ExactDateInfo.BeforeChrist(99, 2, 1, 0));
        }
Exemplo n.º 14
0
        public static IEnumerable <object[]> AddDurationToDateData()
        {
            yield return(new object[]
            {
                ExactDateInfo.AnnoDomini(100, 1, 1, 0),
                Duration.Zero.AddYears(50),
                ExactDateInfo.AnnoDomini(150, 1, 1, 0)
            });

            yield return(new object[]
            {
                ExactDateInfo.BeforeChrist(26, 1, 1, 0),
                Duration.Zero.AddYears(50),
                ExactDateInfo.AnnoDomini(25, 1, 1, 0)
            });

            yield return(new object[]
            {
                ExactDateInfo.AnnoDomini(10, 1, 1, 0),
                Duration.Zero.AddYears(-50),
                ExactDateInfo.BeforeChrist(41, 1, 1, 0)
            });
        }
Exemplo n.º 15
0
        public static IEnumerable <object[]> DurationToDateData()
        {
            yield return(new object[]
            {
                Duration.Zero,
                ExactDateInfo.AnnoDomini(1, 1, 1, 0)
            });

            yield return(new object[]
            {
                Duration.Zero.AddYears(5),
                ExactDateInfo.AnnoDomini(6, 1, 1, 0)
            });

            yield return(new object[]
            {
                Duration.Zero.AddMonths(3),
                ExactDateInfo.AnnoDomini(1, 4, 1, 0)
            });

            yield return(new object[]
            {
                Duration.Zero.AddDays(13),
                ExactDateInfo.AnnoDomini(1, 1, 14, 0)
            });

            yield return(new object[]
            {
                Duration.Zero.AddHours(20),
                ExactDateInfo.AnnoDomini(1, 1, 1, 20)
            });

            yield return(new object[]
            {
                Duration.Zero
                .AddYears(1000000 - 1)
                .AddMonths(12 - 1)
                .AddDays(31 - 1)
                .AddHours(23),
                ExactDateInfo.AnnoDomini(1000000, 12, 31, 23)
            });

            yield return(new object[]
            {
                Duration.Zero.AddYears(-1),
                ExactDateInfo.BeforeChrist(1, 1, 1, 0)
            });

            yield return(new object[]
            {
                Duration.Zero.AddYears(-5).AddMonths(4),
                ExactDateInfo.BeforeChrist(5, 5, 1, 0)
            });

            yield return(new object[]
            {
                Duration.Zero.AddYears(-5).AddDays(12),
                ExactDateInfo.BeforeChrist(5, 1, 13, 0)
            });

            yield return(new object[]
            {
                Duration.Zero.AddYears(-5).AddHours(21),
                ExactDateInfo.BeforeChrist(5, 1, 1, 21)
            });

            yield return(new object[]
            {
                Duration.Zero
                .AddYears(-5000000)
                .AddMonths(12 - 1)
                .AddDays(31 - 1)
                .AddHours(23),
                ExactDateInfo.BeforeChrist(5000000, 12, 31, 23)
            });

            yield return(new object[]
            {
                Duration.Zero
                .AddYears(1979)
                .AddMonths(1)
                .AddDays(29)
                .AddHours(1),
                ExactDateInfo.AnnoDomini(1980, 3, 1, 1)
            });
        }
Exemplo n.º 16
0
 public void Compare_dates_in_different_eras()
 {
     ExactDateInfo.BeforeChrist(100, 1, 1, 0).ShouldBeLessThan(ExactDateInfo.AnnoDomini(100, 1, 1, 0));
     ExactDateInfo.BeforeChrist(200, 1, 1, 0).ShouldBeLessThan(ExactDateInfo.AnnoDomini(100, 1, 1, 0));
 }
Exemplo n.º 17
0
 public void Compare_dates_with_different_years_and_months()
 {
     ExactDateInfo.AnnoDomini(100, 2, 1, 0).ShouldBeLessThan(ExactDateInfo.AnnoDomini(100, 3, 1, 0));
     ExactDateInfo.BeforeChrist(200, 2, 1, 0).ShouldBeLessThan(ExactDateInfo.BeforeChrist(200, 3, 1, 0));
 }