private static Interval?Intersect(Interval left, Interval right)
    {
        Instant start = Instant.Max(left.Start, right.Start);
        Instant end   = Instant.Min(left.End, right.End);

        return(start < end ? new Interval(start, end) : (Interval?)null);
    }
            private void ExtendCurrentItem(Interval?timeRange)
            {
                if (!timeRange.HasValue || !CurrentItem.TimeRange.HasValue)
                {
                    return;
                }

                CurrentItem.TimeRange = new Interval(
                    Instant.Min(CurrentItem.TimeRange.Value.Start, timeRange.Value.Start),
                    Instant.Max(CurrentItem.TimeRange.Value.End, timeRange.Value.End));
            }
Esempio n. 3
0
        public void Min()
        {
            Instant x = Instant.FromUnixTimeTicks(100);
            Instant y = Instant.FromUnixTimeTicks(200);

            Assert.AreEqual(x, Instant.Min(x, y));
            Assert.AreEqual(x, Instant.Min(y, x));
            Assert.AreEqual(Instant.MinValue, Instant.Min(x, Instant.MinValue));
            Assert.AreEqual(Instant.MinValue, Instant.Min(Instant.MinValue, x));
            Assert.AreEqual(x, Instant.Min(Instant.MaxValue, x));
            Assert.AreEqual(x, Instant.Min(x, Instant.MaxValue));
        }
Esempio n. 4
0
        public void Min()
        {
            Instant x = new Instant(100);
            Instant y = new Instant(200);

            Assert.AreEqual(x, Instant.Min(x, y));
            Assert.AreEqual(x, Instant.Min(y, x));
            Assert.AreEqual(Instant.MinValue, Instant.Min(x, Instant.MinValue));
            Assert.AreEqual(Instant.MinValue, Instant.Min(Instant.MinValue, x));
            Assert.AreEqual(x, Instant.Min(Instant.MaxValue, x));
            Assert.AreEqual(x, Instant.Min(x, Instant.MaxValue));
        }
Esempio n. 5
0
        public void Min()
        {
            Instant x = Instant.FromTicksSinceUnixEpoch(100);
            Instant y = Instant.FromTicksSinceUnixEpoch(200);

            Assert.AreEqual(x, Instant.Min(x, y));
            Assert.AreEqual(x, Instant.Min(y, x));
            Assert.AreEqual(Instant.MinValue, Instant.Min(x, Instant.MinValue));
            Assert.AreEqual(Instant.MinValue, Instant.Min(Instant.MinValue, x));
            Assert.AreEqual(x, Instant.Min(Instant.MaxValue, x));
            Assert.AreEqual(x, Instant.Min(x, Instant.MaxValue));
        }
        public virtual void SupportsMin(List <TestEntity <Instant> > testEntities)
        {
            AddToDatabase(testEntities.ToArray());

            var testValue = Instant.Min(testEntities[0].TestProperty, testEntities[0].TestComponent.TestComponentProperty);

            ExecuteWithQueryable(q =>
            {
                var foundEntities = q.Where(x => Instant.Min(x.TestProperty, x.TestComponent.TestComponentProperty) == testValue).Select(x => new { ExposedProperty = Instant.Min(x.TestProperty, x.TestComponent.TestComponentProperty) }).ToList();
                foundEntities.Should().HaveCount(1);
                foundEntities[0].ExposedProperty.Should().Be(testValue);
            });
        }
    /// <summary>
    /// Get a random date between start and end.
    /// </summary>
    public Instant Between(Instant start, Instant end)
    {
        var min = Instant.Min(start, end);
        var max = Instant.Max(start, end);

        var total = max - min;

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

        var part = Duration.FromTicks(partTicks);

        return(min + part);
    }
    /// <summary>
    /// Get a random date between start and end.
    /// </summary>
    public ZonedDateTime Between(ZonedDateTime start, ZonedDateTime end)
    {
        //TODO: check for mis matched zones?
        var min = Instant.Min(start.ToInstant(), end.ToInstant());
        var max = Instant.Max(start.ToInstant(), end.ToInstant());

        var total = max - min;

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

        var part = Duration.FromTicks(partTicks);

        return(new(min + part, start.Zone));
    }
    static Duration GetAvailableOverlap(
        LocalDate date,
        Availability avail1,
        Availability avail2)
    {
        // TODO: Check that the rules of InZoneLeniently are what you want.
        // Be careful, as you could end up with an end before a start...
        var start1 = (date + avail1.Start).InZoneLeniently(avail1.Zone);
        var end1   = (date + avail1.End).InZoneLeniently(avail1.Zone);

        var start2 = (date + avail2.Start).InZoneLeniently(avail2.Zone);
        var end2   = (date + avail2.End).InZoneLeniently(avail2.Zone);

        var latestStart = Instant.Max(start1.ToInstant(), start2.ToInstant());
        var earliestEnd = Instant.Min(end1.ToInstant(), end2.ToInstant());

        // Never return a negative duration... return zero of there's no overlap.
        // Noda Time should have Duration.Max really...
        var overlap = earliestEnd - latestStart;

        return(overlap < Duration.Zero ? Duration.Zero : overlap);
    }
 public virtual void SupportsMinFromParameter(Instant testInstant)
 {
     SupportsPropertyOrMethod(x => Instant.Min(x, testInstant));
 }
 private Instant GetEffectiveEnd(ZoneInterval zoneInterval) =>
 CheckOption(options, Options.MatchStartAndEndTransitions)
         ? zoneInterval.RawEnd : Instant.Min(zoneInterval.RawEnd, interval.End);