当前位置: 首页>>代码示例>>C#>>正文


C# TimePeriodCollection.IntersectionPeriods方法代码示例

本文整理汇总了C#中Itenso.TimePeriod.TimePeriodCollection.IntersectionPeriods方法的典型用法代码示例。如果您正苦于以下问题:C# TimePeriodCollection.IntersectionPeriods方法的具体用法?C# TimePeriodCollection.IntersectionPeriods怎么用?C# TimePeriodCollection.IntersectionPeriods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Itenso.TimePeriod.TimePeriodCollection的用法示例。


在下文中一共展示了TimePeriodCollection.IntersectionPeriods方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IntersectionPeriodsTimePeriodTest

        public void IntersectionPeriodsTimePeriodTest()
        {
            DateTime now = ClockProxy.Clock.Now;
            TimeRange timeRange1 = new TimeRange( new DateTime( now.Year, now.Month, 8 ), new DateTime( now.Year, now.Month, 18 ) );
            TimeRange timeRange2 = new TimeRange( new DateTime( now.Year, now.Month, 10 ), new DateTime( now.Year, now.Month, 11 ) );
            TimeRange timeRange3 = new TimeRange( new DateTime( now.Year, now.Month, 13 ), new DateTime( now.Year, now.Month, 15 ) );
            TimeRange timeRange4 = new TimeRange( new DateTime( now.Year, now.Month, 9 ), new DateTime( now.Year, now.Month, 13 ) );
            TimeRange timeRange5 = new TimeRange( new DateTime( now.Year, now.Month, 15 ), new DateTime( now.Year, now.Month, 17 ) );

            TimePeriodCollection timePeriods = new TimePeriodCollection();
            timePeriods.Add( timeRange1 );
            timePeriods.Add( timeRange2 );
            timePeriods.Add( timeRange3 );
            timePeriods.Add( timeRange4 );
            timePeriods.Add( timeRange5 );

            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange1 ).Count, 5 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange2 ).Count, 3 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange3 ).Count, 4 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange4 ).Count, 4 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange5 ).Count, 3 );

            ITimeRange test1 = timeRange1.Copy( new TimeSpan( 100, 0, 0, 0 ).Negate() );
            ITimePeriodCollection insidePeriods1 = timePeriods.IntersectionPeriods( test1 );
            Assert.AreEqual( insidePeriods1.Count, 0 );

            ITimeRange test2 = timeRange1.Copy( new TimeSpan( 100, 0, 0, 0 ) );
            ITimePeriodCollection insidePeriods2 = timePeriods.IntersectionPeriods( test2 );
            Assert.AreEqual( insidePeriods2.Count, 0 );

            TimeRange test3 = new TimeRange( new DateTime( now.Year, now.Month, 9 ), new DateTime( now.Year, now.Month, 11 ) );
            ITimePeriodCollection insidePeriods3 = timePeriods.IntersectionPeriods( test3 );
            Assert.AreEqual( insidePeriods3.Count, 3 );

            TimeRange test4 = new TimeRange( new DateTime( now.Year, now.Month, 14 ), new DateTime( now.Year, now.Month, 17 ) );
            ITimePeriodCollection insidePeriods4 = timePeriods.IntersectionPeriods( test4 );
            Assert.AreEqual( insidePeriods4.Count, 3 );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:38,代码来源:TimePeriodCollectionTest.cs

示例2: IntersectionPeriodsDateTimeTest

        public void IntersectionPeriodsDateTimeTest()
        {
            DateTime now = ClockProxy.Clock.Now;
            TimeRange timeRange1 = new TimeRange( new DateTime( now.Year, now.Month, 8 ), new DateTime( now.Year, now.Month, 18 ) );
            TimeRange timeRange2 = new TimeRange( new DateTime( now.Year, now.Month, 10 ), new DateTime( now.Year, now.Month, 11 ) );
            TimeRange timeRange3 = new TimeRange( new DateTime( now.Year, now.Month, 13 ), new DateTime( now.Year, now.Month, 15 ) );
            TimeRange timeRange4 = new TimeRange( new DateTime( now.Year, now.Month, 9 ), new DateTime( now.Year, now.Month, 14 ) );
            TimeRange timeRange5 = new TimeRange( new DateTime( now.Year, now.Month, 16 ), new DateTime( now.Year, now.Month, 17 ) );

            TimePeriodCollection timePeriods = new TimePeriodCollection();
            timePeriods.Add( timeRange1 );
            timePeriods.Add( timeRange2 );
            timePeriods.Add( timeRange3 );
            timePeriods.Add( timeRange4 );
            timePeriods.Add( timeRange5 );

            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange1.Start ).Count, 1 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange1.End ).Count, 1 );

            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange2.Start ).Count, 3 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange2.End ).Count, 3 );

            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange3.Start ).Count, 3 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange3.End ).Count, 2 );

            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange4.Start ).Count, 2 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange4.End ).Count, 3 );

            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange5.Start ).Count, 2 );
            Assert.AreEqual( timePeriods.IntersectionPeriods( timeRange5.End ).Count, 2 );

            DateTime test1 = timeRange1.Start.AddMilliseconds( -1 );
            ITimePeriodCollection insidePeriods1 = timePeriods.IntersectionPeriods( test1 );
            Assert.AreEqual( insidePeriods1.Count, 0 );

            DateTime test2 = timeRange1.End.AddMilliseconds( 1 );
            ITimePeriodCollection insidePeriods2 = timePeriods.IntersectionPeriods( test2 );
            Assert.AreEqual( insidePeriods2.Count, 0 );

            DateTime test3 = new DateTime( now.Year, now.Month, 12 );
            ITimePeriodCollection insidePeriods3 = timePeriods.IntersectionPeriods( test3 );
            Assert.AreEqual( insidePeriods3.Count, 2 );

            DateTime test4 = new DateTime( now.Year, now.Month, 14 );
            ITimePeriodCollection insidePeriods4 = timePeriods.IntersectionPeriods( test4 );
            Assert.AreEqual( insidePeriods4.Count, 3 );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:47,代码来源:TimePeriodCollectionTest.cs

示例3: TimeLinePeriodsSample

        public void TimeLinePeriodsSample()
        {
            TimePeriodCollection periods = new TimePeriodCollection();
            periods.Add( new IdTimeRange( 1, new DateTime( 2000, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 2, new DateTime( 2000, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 3, new DateTime( 2000, 1, 1 ), new DateTime( 2009, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 3, new DateTime( 2010, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 4, new DateTime( 2000, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 5, new DateTime( 2000, 1, 1 ), new DateTime( 2014, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 5, new DateTime( 2015, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            foreach ( ITimePeriod period in periods )
            {
                Console.WriteLine( "Period: " + period );
            }

            // time line with all period start and end moments
            ITimeLineMomentCollection moments = new TimeLineMomentCollection();
            moments.AddAll( periods );
            DateTime start = periods.Start;
            foreach ( ITimeLineMoment moment in moments )
            {
                if ( moment.EndCount <= 0 ) // search the next period end
                {
                    continue;
                }
                DateTime end = moment.Moment;
                TimeRange timeRange = new TimeRange( start, end );
                Console.WriteLine( "Period: {0}", timeRange );
                ITimePeriodCollection intersections = periods.IntersectionPeriods( timeRange );
                foreach ( ITimePeriod intersection in intersections )
                {
                    Console.WriteLine( "  Intersection: {0}", intersection );
                }
                start = moment.Moment;
            }
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:36,代码来源:CommunitySamples.cs

示例4: TimePeriodCollectionSample

        public void TimePeriodCollectionSample()
        {
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            DateTime testDay = new DateTime( 2010, 7, 23 );

            // --- items ---
            timePeriods.Add( new TimeRange( TimeTrim.Hour( testDay, 8 ), TimeTrim.Hour( testDay, 11 ) ) );
            timePeriods.Add( new TimeBlock( TimeTrim.Hour( testDay, 10 ), Duration.Hours( 3 ) ) );
            timePeriods.Add( new TimeRange( TimeTrim.Hour( testDay, 16, 15 ), TimeTrim.Hour( testDay, 18, 45 ) ) );
            timePeriods.Add( new TimeRange( TimeTrim.Hour( testDay, 14 ), TimeTrim.Hour( testDay, 15, 30 ) ) );
            Console.WriteLine( "TimePeriodCollection: " + timePeriods );
            // > TimePeriodCollection: Count = 4; 23.07.2010 08:00:00 - 18:45:00 | 0.10:45
            Console.WriteLine( "TimePeriodCollection.Items" );
            foreach ( ITimePeriod timePeriod in timePeriods )
            {
                Console.WriteLine( "Item: " + timePeriod );
            }
            // > Item: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Item: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00
            // > Item: 23.07.2010 16:15:00 - 18:45:00 | 02:30:00
            // > Item: 23.07.2010 14:00:00 - 15:30:00 | 01:30:00

            // --- intersection by moment ---
            DateTime intersectionMoment = new DateTime( 2010, 7, 23, 10, 30, 0 );
            ITimePeriodCollection momentIntersections = timePeriods.IntersectionPeriods( intersectionMoment );
            Console.WriteLine( "TimePeriodCollection.IntesectionPeriods of " + intersectionMoment );
            // > TimePeriodCollection.IntesectionPeriods of 23.07.2010 10:30:00
            foreach ( ITimePeriod momentIntersection in momentIntersections )
            {
                Console.WriteLine( "Intersection: " + momentIntersection );
            }
            // > Intersection: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Intersection: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00

            // --- intersection by period ---
            TimeRange intersectionPeriod = new TimeRange( TimeTrim.Hour( testDay, 9 ), TimeTrim.Hour( testDay, 14, 30 ) );
            ITimePeriodCollection periodIntersections = timePeriods.IntersectionPeriods( intersectionPeriod );
            Console.WriteLine( "TimePeriodCollection.IntesectionPeriods of " + intersectionPeriod );
            // > TimePeriodCollection.IntesectionPeriods of 23.07.2010 09:00:00 - 14:30:00 | 0.05:30
            foreach ( ITimePeriod periodIntersection in periodIntersections )
            {
                Console.WriteLine( "Intersection: " + periodIntersection );
            }
            // > Intersection: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Intersection: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00
            // > Intersection: 23.07.2010 14:00:00 - 15:30:00 | 01:30:00
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:48,代码来源:ArticleSamples.cs

示例5: CombinedPeriodsSample

        public void CombinedPeriodsSample()
        {
            TimePeriodCollection periods = new TimePeriodCollection();
            periods.Add( new IdTimeRange( 1, new DateTime( 2000, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 2, new DateTime( 2000, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 3, new DateTime( 2000, 1, 1 ), new DateTime( 2009, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 3, new DateTime( 2010, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 4, new DateTime( 2000, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 5, new DateTime( 2000, 1, 1 ), new DateTime( 2014, 12, 31 ) ) );
            periods.Add( new IdTimeRange( 5, new DateTime( 2015, 1, 1 ), new DateTime( 2019, 12, 31 ) ) );
            foreach ( ITimePeriod period in periods )
            {
                Console.WriteLine( "Period: " + period );
            }

            TimeRange test1 = new TimeRange( new DateTime( 2000, 1, 1 ), new DateTime( 2009, 12, 31 ) );
            ITimePeriodCollection intersections1 = periods.IntersectionPeriods( test1 );
            foreach ( ITimePeriod intersection1 in intersections1 )
            {
                Console.WriteLine( "Intersection of {0}: {1}", test1, intersection1 );
            }

            TimeRange test2 = new TimeRange( new DateTime( 2010, 1, 1 ), new DateTime( 2014, 12, 31 ) );
            ITimePeriodCollection intersections2 = periods.IntersectionPeriods( test2 );
            foreach ( ITimePeriod intersection2 in intersections2 )
            {
                Console.WriteLine( "Intersection of {0}: {1}", test2, intersection2 );
            }

            TimeRange test3 = new TimeRange( new DateTime( 2015, 1, 1 ), new DateTime( 2019, 12, 31 ) );
            ITimePeriodCollection intersections3 = periods.IntersectionPeriods( test3 );
            foreach ( ITimePeriod intersection3 in intersections3 )
            {
                Console.WriteLine( "Intersection of {0}: {1}", test3, intersection3 );
            }
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:36,代码来源:CommunitySamples.cs


注:本文中的Itenso.TimePeriod.TimePeriodCollection.IntersectionPeriods方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。