Itenso.TimePeriod.TimeInterval.GetIntersection C# (CSharp) Method

GetIntersection() public method

public GetIntersection ( ITimePeriod period ) : ITimeInterval
period ITimePeriod
return ITimeInterval
        public virtual ITimeInterval GetIntersection( ITimePeriod period )
        {
            if ( period == null )
            {
                throw new ArgumentNullException( "period" );
            }
            if ( !IntersectsWith( period ) )
            {
                return null;
            }
            DateTime start = Start;
            DateTime end = End;
            DateTime periodStart = period.Start;
            DateTime periodEnd = period.End;
            return new TimeInterval(
                periodStart > start ? periodStart : start,
                periodEnd < end ? periodEnd : end,
                IntervalEdge.Closed,
                IntervalEdge.Closed,
                IsIntervalEnabled,
                IsReadOnly );
        }

Usage Example

Exemplo n.º 1
0
        public void TouchingIntervalTest()
        {
            TimeInterval timeInterval1 = new TimeInterval( start, end );
            TimeInterval timeInterval2 = new TimeInterval( end, end.AddHours( 1 ) );

            Assert.AreNotEqual( timeInterval1.GetIntersection( timeInterval2 ), null );
            Assert.AreEqual( timeInterval1.IntersectsWith( timeInterval2 ), true );
            Assert.AreEqual( timeInterval1.GetRelation( timeInterval2 ), PeriodRelation.EndTouching );
            Assert.AreEqual( timeInterval2.GetRelation( timeInterval1 ), PeriodRelation.StartTouching );

            timeInterval1.EndEdge = IntervalEdge.Open;
            Assert.AreEqual( timeInterval1.GetIntersection( timeInterval2 ), null );
            Assert.AreEqual( timeInterval1.IntersectsWith( timeInterval2 ), false );
            Assert.AreEqual( timeInterval1.GetRelation( timeInterval2 ), PeriodRelation.Before );
            Assert.AreEqual( timeInterval2.GetRelation( timeInterval1 ), PeriodRelation.After );

            timeInterval1.EndEdge = IntervalEdge.Closed;
            Assert.AreNotEqual( timeInterval1.GetIntersection( timeInterval2 ), null );
            Assert.AreEqual( timeInterval1.IntersectsWith( timeInterval2 ), true );
            Assert.AreEqual( timeInterval1.GetRelation( timeInterval2 ), PeriodRelation.EndTouching );
            Assert.AreEqual( timeInterval2.GetRelation( timeInterval1 ), PeriodRelation.StartTouching );

            timeInterval2.StartEdge = IntervalEdge.Open;
            Assert.AreEqual( timeInterval1.GetIntersection( timeInterval2 ), null );
            Assert.AreEqual( timeInterval1.IntersectsWith( timeInterval2 ), false );
            Assert.AreEqual( timeInterval1.GetRelation( timeInterval2 ), PeriodRelation.Before );
            Assert.AreEqual( timeInterval2.GetRelation( timeInterval1 ), PeriodRelation.After );

            timeInterval2.StartEdge = IntervalEdge.Closed;
            Assert.AreNotEqual( timeInterval1.GetIntersection( timeInterval2 ), null );
            Assert.AreEqual( timeInterval1.IntersectsWith( timeInterval2 ), true );
            Assert.AreEqual( timeInterval1.GetRelation( timeInterval2 ), PeriodRelation.EndTouching );
            Assert.AreEqual( timeInterval2.GetRelation( timeInterval1 ), PeriodRelation.StartTouching );
        }
All Usage Examples Of Itenso.TimePeriod.TimeInterval::GetIntersection