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


C# TimeRange.GetIntersection方法代码示例

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


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

示例1: TimeRangeSample

        public void TimeRangeSample()
        {
            // --- time range 1 ---
            TimeRange timeRange1 = new TimeRange(
                new DateTime( 2011, 2, 22, 14, 0, 0 ),
                new DateTime( 2011, 2, 22, 18, 0, 0 ) );
            Console.WriteLine( "TimeRange1: " + timeRange1 );
            // > TimeRange1: 22.02.2011 14:00:00 - 18:00:00 | 04:00:00

            // --- time range 2 ---
            TimeRange timeRange2 = new TimeRange(
                new DateTime( 2011, 2, 22, 15, 0, 0 ),
                new TimeSpan( 2, 0, 0 ) );
            Console.WriteLine( "TimeRange2: " + timeRange2 );
            // > TimeRange2: 22.02.2011 15:00:00 - 17:00:00 | 02:00:00

            // --- time range 3 ---
            TimeRange timeRange3 = new TimeRange(
                new DateTime( 2011, 2, 22, 16, 0, 0 ),
                new DateTime( 2011, 2, 22, 21, 0, 0 ) );
            Console.WriteLine( "TimeRange3: " + timeRange3 );
            // > TimeRange3: 22.02.2011 16:00:00 - 21:00:00 | 05:00:00

            // --- relation ---
            Console.WriteLine( "TimeRange1.GetRelation( TimeRange2 ): " + timeRange1.GetRelation( timeRange2 ) );
            // > TimeRange1.GetRelation( TimeRange2 ): Enclosing
            Console.WriteLine( "TimeRange1.GetRelation( TimeRange3 ): " + timeRange1.GetRelation( timeRange3 ) );
            // > TimeRange1.GetRelation( TimeRange3 ): EndInside
            Console.WriteLine( "TimeRange3.GetRelation( TimeRange2 ): " + timeRange3.GetRelation( timeRange2 ) );
            // > TimeRange3.GetRelation( TimeRange2 ): StartInside

            // --- intersection ---
            Console.WriteLine( "TimeRange1.GetIntersection( TimeRange2 ): " + timeRange1.GetIntersection( timeRange2 ) );
            // > TimeRange1.GetIntersection( TimeRange2 ): 22.02.2011 15:00:00 - 17:00:00 | 02:00:00
            Console.WriteLine( "TimeRange1.GetIntersection( TimeRange3 ): " + timeRange1.GetIntersection( timeRange3 ) );
            // > TimeRange1.GetIntersection( TimeRange3 ): 22.02.2011 16:00:00 - 18:00:00 | 02:00:00
            Console.WriteLine( "TimeRange3.GetIntersection( TimeRange2 ): " + timeRange3.GetIntersection( timeRange2 ) );
            // > TimeRange3.GetIntersection( TimeRange2 ): 22.02.2011 16:00:00 - 17:00:00 | 01:00:00
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:39,代码来源:ArticleSamples.cs

示例2: CalcWorkingPeriod

        // ----------------------------------------------------------------------
        public TimeSpan CalcWorkingPeriod( DateTime start, DateTime end,
            ITimePeriodCollection excludePeriods = null)
        {
            if ( start.Equals( end ) )
            {
                return TimeSpan.Zero;
            }

            // test range
            TimeRange testRange = new TimeRange( start, end );

            // search range
            DateTime searchStart = new Day( testRange.Start ).Start;
            DateTime serachEnd = new Day( testRange.End ).GetNextDay().Start;
            TimeRange searchPeriod = new TimeRange( searchStart, serachEnd );

            // search filter
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();
            filter.AddWorkingWeekDays(); // working days
            if ( excludePeriods != null )
            {
                filter.ExcludePeriods.AddAll( excludePeriods );
            }
            filter.CollectingHours.Add( new HourRange( 07, 12 ) ); // working hours
            filter.CollectingHours.Add( new HourRange( 13, 19 ) ); // working hours

            // collect working hours
            TimeCalendar calendar = new TimeCalendar( new TimeCalendarConfig { EndOffset = TimeSpan.Zero } );
            CalendarPeriodCollector collector = new CalendarPeriodCollector( filter, searchPeriod, SeekDirection.Forward, calendar );
            collector.CollectHours();

            TimeSpan workingPeriod = new TimeSpan();
            foreach ( ICalendarTimeRange period in collector.Periods )
            {
                // get the intersection of the test-range and the day working-hours
                ITimePeriod intersection = testRange.GetIntersection( period );
                if ( intersection == null )
                {
                    continue;
                }
                workingPeriod = workingPeriod.Add( intersection.Duration );
            }
            return workingPeriod;
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:45,代码来源:CommunitySamples.cs

示例3: GetIntersectionTest

        public void GetIntersectionTest()
        {
            TimeRange readOnlyTimeRange = new TimeRange( start, end );
            Assert.AreEqual( readOnlyTimeRange.GetIntersection( readOnlyTimeRange ), new TimeRange( readOnlyTimeRange ) );

            TimeRange timeRange = new TimeRange( start, end );

            // before
            ITimeRange before1 = timeRange.GetIntersection( new TimeRange( start.AddHours( -2 ), start.AddHours( -1 ) ) );
            Assert.AreEqual( before1, null );
            ITimeRange before2 = timeRange.GetIntersection( new TimeRange( start.AddMilliseconds( -1 ), start ) );
            Assert.AreEqual( before2, new TimeRange( start ) );
            ITimeRange before3 = timeRange.GetIntersection( new TimeRange( start.AddMilliseconds( -1 ), start.AddMilliseconds( 1 ) ) );
            Assert.AreEqual( before3, new TimeRange( start, start.AddMilliseconds( 1 ) ) );

            // after
            ITimeRange after1 = timeRange.GetIntersection( new TimeRange( end.AddHours( 1 ), end.AddHours( 2 ) ) );
            Assert.AreEqual( after1, null );
            ITimeRange after2 = timeRange.GetIntersection( new TimeRange( end, end.AddMilliseconds( 1 ) ) );
            Assert.AreEqual( after2, new TimeRange( end ) );
            ITimeRange after3 = timeRange.GetIntersection( new TimeRange( end.AddMilliseconds( -1 ), end.AddMilliseconds( 1 ) ) );
            Assert.AreEqual( after3, new TimeRange( end.AddMilliseconds( -1 ), end ) );

            // intersect
            Assert.AreEqual( timeRange.GetIntersection( timeRange ), timeRange );
            ITimeRange itersect1 = timeRange.GetIntersection( new TimeRange( start.AddMilliseconds( -1 ), end.AddMilliseconds( 1 ) ) );
            Assert.AreEqual( itersect1, timeRange );
            ITimeRange itersect2 = timeRange.GetIntersection( new TimeRange( start.AddMilliseconds( 1 ), end.AddMilliseconds( -1 ) ) );
            Assert.AreEqual( itersect2, new TimeRange( start.AddMilliseconds( 1 ), end.AddMilliseconds( -1 ) ) );
        }
开发者ID:HoLoveSalt,项目名称:showhotel,代码行数:30,代码来源:TimeRangeTest.cs

示例4: GetCommonIntersection

        // ----------------------------------------------------------------------
        private ITimePeriod GetCommonIntersection( ITimePeriodCollection periods )
        {
            if ( periods.Count == 0 )
            {
                return null;
            }

            ITimeRange timeRange = new TimeRange( periods[ 0 ] );
            if ( periods.Count > 1 )
            {
                for ( int i = 1; i < periods.Count; i++ )
                {
                    timeRange = timeRange.GetIntersection( periods[ i ] );
                    if ( timeRange == null )
                    {
                        return null;
                    }
                }
            }

            return timeRange;
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:23,代码来源:CommunitySamples.cs


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