Пример #1
0
        public void MinMax_DifferentCalendars_Throws()
        {
            LocalDateTime ldt1 = new LocalDateTime(2011, 1, 2, 2, 20);
            LocalDateTime ldt2 = new LocalDateTime(1500, 1, 1, 5, 10, CalendarSystem.Julian);

            Assert.Throws <ArgumentException>(() => LocalDateTime.Max(ldt1, ldt2));
            Assert.Throws <ArgumentException>(() => LocalDateTime.Min(ldt1, ldt2));
        }
        /// <summary>
        /// Get a random date between start and end.
        /// </summary>
        public LocalDateTime Between(LocalDateTime start, LocalDateTime end)
        {
            var min = LocalDateTime.Min(start, end);
            var max = LocalDateTime.Max(start, end);

            var periodBetween = Period.Between(min, max, PeriodUnits.Ticks);

            return(min.PlusTicks(Random.Long(0, periodBetween.Ticks)));
        }
Пример #3
0
        public void MinMax_SameCalendar()
        {
            LocalDateTime ldt1 = new LocalDateTime(1500, 1, 1, 7, 20, CalendarSystem.Julian);
            LocalDateTime ldt2 = new LocalDateTime(1500, 1, 1, 5, 10, CalendarSystem.Julian);

            Assert.AreEqual(ldt1, LocalDateTime.Max(ldt1, ldt2));
            Assert.AreEqual(ldt1, LocalDateTime.Max(ldt2, ldt1));
            Assert.AreEqual(ldt2, LocalDateTime.Min(ldt1, ldt2));
            Assert.AreEqual(ldt2, LocalDateTime.Min(ldt2, ldt1));
        }
        /// <summary>
        /// Get a random date between start and end.
        /// </summary>
        public LocalDateTime Between(LocalDateTime start, LocalDateTime end)
        {
            var min = LocalDateTime.Min(start, end);
            var max = LocalDateTime.Max(start, end);

            var total = max - min;


            var partTicks = Random.Double() * total.ToDuration().TotalTicks;

            return(min.PlusTicks(Convert.ToInt64(partTicks)));
        }
 public virtual void SupportsMin(LocalDateTime localDateTime)
 {
     SupportsPropertyOrMethod(x => LocalDateTime.Min(x, localDateTime));
 }