Ejemplo n.º 1
0
 public void Duration_from_Christ_birth_of_dates_in_previous_era()
 {
     Duration.GetDurationFromChristBirth(PartialDateInfo.BeforeChrist(11)).ShouldBe(Duration.Zero.AddYears(-11));
     Duration.GetDurationFromChristBirth(PartialDateInfo.BeforeChrist(300, 4)).ShouldBe(Duration.Zero.AddYears(-300).AddMonths(3));
     Duration.GetDurationFromChristBirth(PartialDateInfo.BeforeChrist(4000, 9, 10)).ShouldBe(Duration.Zero.AddYears(-4000).AddMonths(8).AddDays(9));
     Duration.GetDurationFromChristBirth(PartialDateInfo.BeforeChrist(57, 3, 22, 5)).ShouldBe(Duration.Zero.AddYears(-57).AddMonths(2).AddDays(21).AddHours(5));
 }
Ejemplo n.º 2
0
 public void Duration_from_Christ_birth_of_our_era_start()
 {
     Duration.GetDurationFromChristBirth(PartialDateInfo.AnnoDomini(1)).ShouldBe(Duration.Zero);
     Duration.GetDurationFromChristBirth(PartialDateInfo.AnnoDomini(1, 1)).ShouldBe(Duration.Zero);
     Duration.GetDurationFromChristBirth(PartialDateInfo.AnnoDomini(1, 1, 1)).ShouldBe(Duration.Zero);
     Duration.GetDurationFromChristBirth(PartialDateInfo.AnnoDomini(1, 1, 1, 0)).ShouldBe(Duration.Zero);
 }
Ejemplo n.º 3
0
 public void Compare_dates_with_only_part_of_years_months_and_days()
 {
     PartialDateInfo.AnnoDomini(100).ShouldBeLessThan(PartialDateInfo.AnnoDomini(100, 2, 15));
     PartialDateInfo.AnnoDomini(100, 2).ShouldBeLessThan(PartialDateInfo.AnnoDomini(100, 2, 15));
     PartialDateInfo.BeforeChrist(200).ShouldBeLessThan(PartialDateInfo.BeforeChrist(200, 3, 15));
     PartialDateInfo.BeforeChrist(200, 3).ShouldBeLessThan(PartialDateInfo.BeforeChrist(200, 3, 15));
 }
Ejemplo n.º 4
0
 public void Duration_from_Christ_birth_of_dates_in_our_era()
 {
     Duration.GetDurationFromChristBirth(PartialDateInfo.AnnoDomini(100)).ShouldBe(Duration.Zero.AddYears(99));
     Duration.GetDurationFromChristBirth(PartialDateInfo.AnnoDomini(15, 3)).ShouldBe(Duration.Zero.AddYears(14).AddMonths(2));
     Duration.GetDurationFromChristBirth(PartialDateInfo.AnnoDomini(1941, 6, 21)).ShouldBe(Duration.Zero.AddYears(1940).AddMonths(5).AddDays(20));
     Duration.GetDurationFromChristBirth(PartialDateInfo.AnnoDomini(1, 7, 5, 13)).ShouldBe(Duration.Zero.AddMonths(6).AddDays(4).AddHours(13));
 }
Ejemplo n.º 5
0
        public void Create_date_with_month_and_day()
        {
            var dateInfo = new PartialDateInfo(Era.AnnoDomini, 124, 3, 14);

            dateInfo.Era.ShouldBe(Era.AnnoDomini);
            dateInfo.Year.ShouldBe(124L);
            dateInfo.Month.ShouldBe(3);
            dateInfo.Day.ShouldBe(14);
            dateInfo.Hour.ShouldBeNull();
        }
Ejemplo n.º 6
0
        public void Create_universe_start_date()
        {
            var dateInfo = new PartialDateInfo(Era.BeforeChrist, 13750000000L);

            dateInfo.Era.ShouldBe(Era.BeforeChrist);
            dateInfo.Year.ShouldBe(13750000000L);
            dateInfo.Month.ShouldBeNull();
            dateInfo.Day.ShouldBeNull();
            dateInfo.Hour.ShouldBeNull();
        }
Ejemplo n.º 7
0
        public void Duration_equality(
            PartialDateInfo date1,
            PartialDateInfo date2,
            PartialDateInfo date3,
            PartialDateInfo date4,
            bool equals)
        {
            var d1 = Duration.GetDurationFromChristBirth(date1)
                     - Duration.GetDurationFromChristBirth(date2);
            var d2 = Duration.GetDurationFromChristBirth(date3)
                     - Duration.GetDurationFromChristBirth(date4);

            (d1 == d2).ShouldBe(equals);
        }
Ejemplo n.º 8
0
        public static IEnumerable <object[]> DurationEqualityData()
        {
            yield return(new object[]
            {
                PartialDateInfo.AnnoDomini(99),
                PartialDateInfo.AnnoDomini(90),
                PartialDateInfo.AnnoDomini(1945),
                PartialDateInfo.AnnoDomini(1936),
                true
            });

            yield return(new object[]
            {
                PartialDateInfo.AnnoDomini(70, 6),
                PartialDateInfo.AnnoDomini(55, 3),
                PartialDateInfo.AnnoDomini(4, 9),
                PartialDateInfo.BeforeChrist(12, 6),
                true
            });

            yield return(new object[]
            {
                PartialDateInfo.AnnoDomini(400, 3, 15),
                PartialDateInfo.AnnoDomini(411, 1, 5),
                PartialDateInfo.BeforeChrist(333, 9, 20),
                PartialDateInfo.BeforeChrist(322, 7, 10),
                true
            });

            yield return(new object[]
            {
                PartialDateInfo.AnnoDomini(2000, 10, 7, 12),
                PartialDateInfo.AnnoDomini(2000, 10, 7, 5),
                PartialDateInfo.BeforeChrist(2000, 10, 6, 2),
                PartialDateInfo.BeforeChrist(2000, 10, 5, 19),
                true
            });

            yield return(new object[]
            {
                PartialDateInfo.AnnoDomini(2000, 10, 7, 12),
                PartialDateInfo.AnnoDomini(2000, 10, 7, 5),
                PartialDateInfo.AnnoDomini(2000, 10, 7, 13),
                PartialDateInfo.AnnoDomini(2000, 10, 7, 5),
                false
            });
        }
Ejemplo n.º 9
0
        private Event GetEventInfo(Event <string, string> @event)
        {
            var eventInfo = new Event
            {
                Content = @event.Description
            };

            if (@event.Place != null)
            {
                eventInfo.PlaceId = @event.Place.Id;
            }

            switch (@event.Start)
            {
            case NowDate _:
            {
                eventInfo.StartIsCurrent = true;
                eventInfo.StartDuration  = null;
                eventInfo.StartNullPart  = null;
                break;
            }

            case SpecificDate d:
            {
                PartialDateInfo pD = d;
                eventInfo.StartIsCurrent = false;
                eventInfo.StartDuration  = Duration.GetDurationFromChristBirth(pD);
                eventInfo.StartNullPart  = pD switch {
                    _ when pD.Month is null => NullableDateParts.Month,
                              _ when pD.Day is null => NullableDateParts.Day,
                              _ when pD.Hour is null => NullableDateParts.Hour,
                              _ => NullableDateParts.Nothing
                };
                break;
            }
            }

            if (@event.End is null)
            {
                eventInfo.EndIsCurrent = null;
                eventInfo.EndDuration  = null;
                eventInfo.EndNullPart  = null;
            }
            else
            {
                switch (@event.End)
                {
                case NowDate _:
                {
                    eventInfo.EndIsCurrent = true;
                    eventInfo.EndDuration  = null;
                    eventInfo.EndNullPart  = null;
                    break;
                }

                case SpecificDate d:
                {
                    PartialDateInfo pD = d;
                    eventInfo.EndIsCurrent = false;
                    eventInfo.EndDuration  = Duration.GetDurationFromChristBirth(pD);
                    eventInfo.EndNullPart  = pD switch
                    {
                        _ when pD.Month is null => NullableDateParts.Month,
                                  _ when pD.Day is null => NullableDateParts.Day,
                                  _ when pD.Hour is null => NullableDateParts.Hour,
                                  _ => NullableDateParts.Nothing
                    };
                    break;
                }
                }
            }

            return(eventInfo);
        }
    }
}
Ejemplo n.º 10
0
 public void Compare_dates_with_different_years_months_days_and_hours()
 {
     PartialDateInfo.AnnoDomini(100, 2, 10, 3).ShouldBeLessThan(PartialDateInfo.AnnoDomini(100, 2, 10, 5));
     PartialDateInfo.BeforeChrist(200, 3, 10, 3).ShouldBeLessThan(PartialDateInfo.BeforeChrist(200, 3, 10, 5));
 }
Ejemplo n.º 11
0
 public void Compare_dates_with_only_years_and_with_years_and_months()
 {
     PartialDateInfo.AnnoDomini(100).ShouldBeLessThan(PartialDateInfo.AnnoDomini(100, 1));
     PartialDateInfo.BeforeChrist(200).ShouldBeLessThan(PartialDateInfo.BeforeChrist(200, 1));
 }
Ejemplo n.º 12
0
 public void Compare_dates_with_different_years()
 {
     PartialDateInfo.AnnoDomini(100).ShouldBeLessThan(PartialDateInfo.AnnoDomini(200));
     PartialDateInfo.BeforeChrist(200).ShouldBeLessThan(PartialDateInfo.BeforeChrist(100));
 }