• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# TimePeriod.TimePeriodCollection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TimePeriodCollection类属于Itenso.TimePeriod命名空间,在下文中一共展示了TimePeriodCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CalendarGetGapTest

        public void CalendarGetGapTest()
        {
            // simmulation of some reservations
            TimePeriodCollection periods = new TimePeriodCollection();
            periods.Add( new Days( 2011, 3, 7, 2 ) );
            periods.Add( new Days( 2011, 3, 16, 2 ) );

            // the overall search range
            CalendarTimeRange limits = new CalendarTimeRange( new DateTime( 2011, 3, 4 ), new DateTime( 2011, 3, 21 ) );
            Days days = new Days( limits.Start, limits.Duration.Days + 1 );
            ITimePeriodCollection dayList = days.GetDays();
            foreach ( Day day in dayList )
            {
                if ( !limits.HasInside( day ) )
                {
                    continue; // outside of the search scope
                }
                if ( day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday )
                {
                    periods.Add( day ); // // exclude weekend day
                }
            }

            TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<TimeRange>( new TimeCalendar() );
            ITimePeriodCollection gaps = gapCalculator.GetGaps( periods, limits );

            Assert.AreEqual( gaps.Count, 4 );
            Assert.IsTrue( gaps[ 0 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 4 ), Duration.Days( 1 ) ) ) );
            Assert.IsTrue( gaps[ 1 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 9 ), Duration.Days( 3 ) ) ) );
            Assert.IsTrue( gaps[ 2 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 14 ), Duration.Days( 2 ) ) ) );
            Assert.IsTrue( gaps[ 3 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 18 ), Duration.Days( 1 ) ) ) );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:32,代码来源:TimeGapCalculatorTest.cs


示例2: GetYears

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetYears()
 {
     TimePeriodCollection years = new TimePeriodCollection();
     for ( int i = 0; i < YearCount; i++ )
     {
         years.Add( new Year( StartYear + i, Calendar ) );
     }
     return years;
 }
开发者ID:jwg4,项目名称:date-difference,代码行数:10,代码来源:Years.cs


示例3: GetWeeks

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetWeeks()
 {
     TimePeriodCollection weeks = new TimePeriodCollection();
     for ( int i = 0; i < WeekCount; i++ )
     {
         weeks.Add( new Week( Year, StartWeek + i, Calendar ) );
     }
     return weeks;
 }
开发者ID:jwg4,项目名称:date-difference,代码行数:10,代码来源:Weeks.cs


示例4: GetDays

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetDays()
 {
     TimePeriodCollection days = new TimePeriodCollection();
     DateTime startDay = new DateTime( StartYear, StartMonth, StartDay );
     for ( int i = 0; i < DayCount; i++ )
     {
         days.Add( new Day( startDay.AddDays( i ), Calendar ) );
     }
     return days;
 }
开发者ID:HoLoveSalt,项目名称:showhotel,代码行数:11,代码来源:Days.cs


示例5: GetMinutes

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetMinutes()
 {
     TimePeriodCollection minutes = new TimePeriodCollection();
     DateTime startMinute = new DateTime( StartYear, StartMonth, StartDay, StartHour, StartMinute, 0 );
     for ( int i = 0; i < MinuteCount; i++ )
     {
         minutes.Add( new Minute( startMinute.AddMinutes( i ), Calendar ) );
     }
     return minutes;
 }
开发者ID:HoLoveSalt,项目名称:showhotel,代码行数:11,代码来源:Minutes.cs


示例6: GetDays

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetDays()
 {
     TimePeriodCollection days = new TimePeriodCollection();
     DateTime startDate = new DateTime( Start.Year, Start.Month, Start.Day );
     for ( int day = 0; day < TimeSpec.DaysPerWeek; day++ )
     {
         days.Add( new Day( startDate.AddDays( day ), Calendar ) );
     }
     return days;
 }
开发者ID:jwg4,项目名称:date-difference,代码行数:11,代码来源:CustomWeek.cs


示例7: GetHours

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetHours()
 {
     TimePeriodCollection hours = new TimePeriodCollection();
     DateTime startHour = new DateTime( StartYear, StartMonth, StartDay, StartHour, 0, 0 );
     for ( int i = 0; i < HourCount; i++ )
     {
         hours.Add( new Hour( startHour.AddHours( i ), Calendar ) );
     }
     return hours;
 }
开发者ID:jwg4,项目名称:date-difference,代码行数:11,代码来源:Hours.cs


示例8: GetQuarters

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetQuarters()
 {
     TimePeriodCollection quarters = new TimePeriodCollection();
     for ( int i = 0; i < QuarterCount; i++ )
     {
         int year;
         YearQuarter quarter;
         TimeTool.AddQuarter( StartYear, StartQuarter, i, out year, out quarter );
         quarters.Add( new Quarter( year, quarter, Calendar ) );
     }
     return quarters;
 }
开发者ID:HoLoveSalt,项目名称:showhotel,代码行数:13,代码来源:Quarters.cs


示例9: GetMonths

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetMonths()
 {
     TimePeriodCollection months = new TimePeriodCollection();
     for ( int i = 0; i < MonthCount; i++ )
     {
         int year;
         YearMonth month;
         TimeTool.AddMonth( StartYear, StartMonth, i, out year, out month );
         months.Add( new Month( year, month, Calendar ) );
     }
     return months;
 }
开发者ID:HoLoveSalt,项目名称:showhotel,代码行数:13,代码来源:Months.cs


示例10: GetHalfyears

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetHalfyears()
 {
     TimePeriodCollection halfyears = new TimePeriodCollection();
     for ( int i = 0; i < HalfyearCount; i++ )
     {
         int year;
         YearHalfyear halfyear;
         TimeTool.AddHalfyear( StartYear, StartHalfyear, i, out year, out halfyear );
         halfyears.Add( new Halfyear( year, halfyear, Calendar ) );
     }
     return halfyears;
 }
开发者ID:HoLoveSalt,项目名称:showhotel,代码行数:13,代码来源:Halfyears.cs


示例11: GetGapTest

        public void GetGapTest()
        {
            DateTime now = ClockProxy.Clock.Now;
            SchoolDay schoolDay = new SchoolDay( now );
            TimePeriodCollection excludePeriods = new TimePeriodCollection();
            TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<TimeRange>();

            excludePeriods.AddAll( schoolDay );

            Assert.AreEqual( gapCalculator.GetGaps( excludePeriods ).Count, 0 );
            Assert.AreEqual( gapCalculator.GetGaps( excludePeriods, schoolDay ).Count, 0 );

            excludePeriods.Clear();
            excludePeriods.Add( schoolDay.Lesson1 );
            excludePeriods.Add( schoolDay.Lesson2 );
            excludePeriods.Add( schoolDay.Lesson3 );
            excludePeriods.Add( schoolDay.Lesson4 );

            ITimePeriodCollection gaps2 = gapCalculator.GetGaps( excludePeriods );
            Assert.AreEqual( gaps2.Count, 3 );
            Assert.IsTrue( gaps2[ 0 ].IsSamePeriod( schoolDay.Break1 ) );
            Assert.IsTrue( gaps2[ 1 ].IsSamePeriod( schoolDay.Break2 ) );
            Assert.IsTrue( gaps2[ 2 ].IsSamePeriod( schoolDay.Break3 ) );

            TimeRange testRange3 = new TimeRange( schoolDay.Lesson1.Start, schoolDay.Lesson4.End );
            ITimePeriodCollection gaps3 = gapCalculator.GetGaps( excludePeriods, testRange3 );
            Assert.AreEqual( gaps3.Count, 3 );
            Assert.IsTrue( gaps3[ 0 ].IsSamePeriod( schoolDay.Break1 ) );
            Assert.IsTrue( gaps3[ 1 ].IsSamePeriod( schoolDay.Break2 ) );
            Assert.IsTrue( gaps3[ 2 ].IsSamePeriod( schoolDay.Break3 ) );

            TimeRange testRange4 = new TimeRange( schoolDay.Start.AddHours( -1 ), schoolDay.End.AddHours( 1 ) );
            ITimePeriodCollection gaps4 = gapCalculator.GetGaps( excludePeriods, testRange4 );
            Assert.AreEqual( gaps4.Count, 5 );
            Assert.IsTrue( gaps4[ 0 ].IsSamePeriod( new TimeRange( testRange4.Start, schoolDay.Start ) ) );
            Assert.IsTrue( gaps4[ 1 ].IsSamePeriod( schoolDay.Break1 ) );
            Assert.IsTrue( gaps4[ 2 ].IsSamePeriod( schoolDay.Break2 ) );
            Assert.IsTrue( gaps4[ 3 ].IsSamePeriod( schoolDay.Break3 ) );
            Assert.IsTrue( gaps4[ 4 ].IsSamePeriod( new TimeRange( testRange4.End, testRange3.End ) ) );

            excludePeriods.Clear();
            excludePeriods.Add( schoolDay.Lesson1 );
            ITimePeriodCollection gaps8 = gapCalculator.GetGaps( excludePeriods, schoolDay.Lesson1 );
            Assert.AreEqual( gaps8.Count, 0 );

            TimeRange testRange9 = new TimeRange( schoolDay.Lesson1.Start.Subtract( new TimeSpan( 1 ) ), schoolDay.Lesson1.End.Add( new TimeSpan( 1 ) ) );
            ITimePeriodCollection gaps9 = gapCalculator.GetGaps( excludePeriods, testRange9 );
            Assert.AreEqual( gaps9.Count, 2 );
            Assert.AreEqual( gaps9[ 0 ].Duration, new TimeSpan( 1 ) );
            Assert.AreEqual( gaps9[ 1 ].Duration, new TimeSpan( 1 ) );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:51,代码来源:TimeGapCalculatorTest.cs


示例12: AddTest

        public void AddTest()
        {
            TimePeriodCollection timePeriods = new TimePeriodCollection();
            Assert.AreEqual( timePeriods.Count, 0 );

            timePeriods.Add( new TimeRange() );
            Assert.AreEqual( timePeriods.Count, 1 );

            timePeriods.Add( new TimeRange() );
            Assert.AreEqual( timePeriods.Count, 2 );

            timePeriods.Clear();
            Assert.AreEqual( timePeriods.Count, 0 );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:14,代码来源:TimePeriodCollectionTest.cs


示例13: AddAllTest

        public void AddAllTest()
        {
            DateTime now = ClockProxy.Clock.Now;
            SchoolDay schoolDay = new SchoolDay( now );
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            Assert.AreEqual( timePeriods.Count, 0 );

            timePeriods.AddAll( schoolDay );
            Assert.AreEqual( timePeriods.Count, schoolDay.Count );

            timePeriods.Clear();
            Assert.AreEqual( timePeriods.Count, 0 );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:14,代码来源:TimePeriodCollectionTest.cs


示例14: TimeRangeCombinedPeriodsTest

        public void TimeRangeCombinedPeriodsTest()
        {
            TimePeriodCollection periods = new TimePeriodCollection();
            DateTime date1 = ClockProxy.Clock.Now;
            DateTime date2 = date1.AddDays( 1 );
            DateTime date3 = date2.AddDays( 1 );
            periods.Add( new TimeRange( date1, date2 ) );
            periods.Add( new TimeRange( date2, date3 ) );

            TimeLine<TimeRange> timeLine = new TimeLine<TimeRange>( periods, null, null );
            ITimePeriodCollection combinedPeriods = timeLine.CombinePeriods();
            Assert.AreEqual( 1, combinedPeriods.Count );
            Assert.AreEqual( new TimeRange( date1, date3 ), combinedPeriods[ 0 ] );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:14,代码来源:TimeLineTest.cs


示例15: GetGaps

        // ----------------------------------------------------------------------
        public IList<MyTimePeriod> GetGaps( IEnumerable<MyTimePeriod> periods )
        {
            TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<TimeRange>();

            TimePeriodCollection calcPeriods = new TimePeriodCollection();
            foreach ( MyTimePeriod period in periods )
            {
                calcPeriods.Add( new TimeRange( period.Start, period.End ) );
            }

            List<MyTimePeriod> gaps = new List<MyTimePeriod>();
            if ( calcPeriods.Count == 0 )
            {
                return gaps;
            }

            ITimePeriodCollection calcCaps = gapCalculator.GetGaps( calcPeriods );
            foreach ( TimeRange calcCap in calcCaps )
            {
                gaps.Add( new MyTimePeriod { Start = calcCap.Start, End = calcCap.End } );
            }

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


示例16: GetMonths

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetMonths()
 {
     TimePeriodCollection months = new TimePeriodCollection();
     DateTime startDate = new DateTime( startYear, (int)YearBaseMonth, 1 );
     int monthCount = quarterCount * TimeSpec.MonthsPerQuarter;
     for ( int i = 0; i < monthCount; i++ )
     {
         months.Add( new Month( startDate.AddMonths( i ), Calendar ) );
     }
     return months;
 }
开发者ID:jwg4,项目名称:date-difference,代码行数:12,代码来源:QuarterTimeRange.cs


示例17: OverlapsWithTest

        public void OverlapsWithTest()
        {
            DateTime now = ClockProxy.Clock.Now;
            TimeSpan offset = Duration.Second;
            TimeRangePeriodRelationTestData testData = new TimeRangePeriodRelationTestData( now, now.AddHours( 1 ), offset );
            TimePeriodCollection timePeriods = new TimePeriodCollection();
            timePeriods.Add( testData.Reference );

            Assert.IsFalse( timePeriods.OverlapsWith( testData.Before ) );
            Assert.IsFalse( timePeriods.OverlapsWith( testData.StartTouching ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.StartInside ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.InsideStartTouching ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.EnclosingStartTouching ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.Enclosing ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.EnclosingEndTouching ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.ExactMatch ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.Inside ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.InsideEndTouching ) );
            Assert.IsTrue( timePeriods.OverlapsWith( testData.EndInside ) );
            Assert.IsFalse( timePeriods.OverlapsWith( testData.EndTouching ) );
            Assert.IsFalse( timePeriods.OverlapsWith( testData.After ) );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:22,代码来源:TimePeriodCollectionTest.cs


示例18: IsSamePeriodTest

        public void IsSamePeriodTest()
        {
            DateTime now = ClockProxy.Clock.Now;
            SchoolDay schoolDay = new SchoolDay( now );
            TimePeriodCollection timePeriods = new TimePeriodCollection( schoolDay );

            Assert.IsTrue( timePeriods.IsSamePeriod( timePeriods ) );
            Assert.IsTrue( timePeriods.IsSamePeriod( schoolDay ) );

            Assert.IsTrue( schoolDay.IsSamePeriod( schoolDay ) );
            Assert.IsTrue( schoolDay.IsSamePeriod( timePeriods ) );

            Assert.IsFalse( timePeriods.IsSamePeriod( TimeBlock.Anytime ) );
            Assert.IsFalse( schoolDay.IsSamePeriod( TimeBlock.Anytime ) );

            timePeriods.RemoveAt( 0 );
            Assert.IsFalse( timePeriods.IsSamePeriod( schoolDay ) );
        }
开发者ID:jwg4,项目名称:date-difference,代码行数:18,代码来源:TimePeriodCollectionTest.cs


示例19: CalculateEnd

        // ----------------------------------------------------------------------
        protected DateTime? CalculateEnd( DateTime start, TimeSpan offset,
            SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode, out TimeSpan? remaining)
        {
            if ( offset < TimeSpan.Zero )
            {
                throw new InvalidOperationException( "time span must be positive" );
            }

            remaining = offset;

            // search periods
            TimePeriodCollection searchPeriods = new TimePeriodCollection( includePeriods );

            // no search periods specified: search anytime
            if ( searchPeriods.Count == 0 )
            {
                searchPeriods.Add( TimeRange.Anytime );
            }

            // available periods
            ITimePeriodCollection availablePeriods = new TimePeriodCollection();

            // no exclude periods specified: use all search periods
            if ( excludePeriods.Count == 0 )
            {
                availablePeriods.AddAll( searchPeriods );
            }
            else // remove exclude periods
            {
                TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<TimeRange>();
                foreach ( ITimePeriod searchPeriod in searchPeriods )
                {

                    // no overlaps: use the entire search range
                    if ( !excludePeriods.HasOverlapPeriods( searchPeriod ) )
                    {
                        availablePeriods.Add( searchPeriod );
                    }
                    else // add gaps of search period using the exclude periods
                    {
                        availablePeriods.AddAll( gapCalculator.GetGaps( excludePeriods, searchPeriod ) );
                    }
                }
            }

            // no periods available
            if ( availablePeriods.Count == 0 )
            {
                return null;
            }

            // combine the available periods, ensure no overlapping
            // used for FindNextPeriod/FindPreviousPeriod
            if ( availablePeriods.Count > 1 )
            {
                TimePeriodCombiner<TimeRange> periodCombiner = new TimePeriodCombiner<TimeRange>();
                availablePeriods = periodCombiner.CombinePeriods( availablePeriods );
            }

            // find the starting search period
            ITimePeriod startPeriod = null;
            DateTime seekMoment = start;
            switch ( seekDirection )
            {
                case SeekDirection.Forward:
                    startPeriod = FindNextPeriod( start, availablePeriods, out seekMoment );
                    break;
                case SeekDirection.Backward:
                    startPeriod = FindPreviousPeriod( start, availablePeriods, out seekMoment );
                    break;
            }

            // no starting period available
            if ( startPeriod == null )
            {
                return null;
            }

            // no offset: use the search staring position
            // maybe moved to the next available search period
            if ( offset == TimeSpan.Zero )
            {
                return seekMoment;
            }

            // setup destination search
            switch ( seekDirection )
            {
                case SeekDirection.Forward:
                    for ( int i = availablePeriods.IndexOf( startPeriod ); i < availablePeriods.Count; i++ )
                    {
                        ITimePeriod gap = availablePeriods[ i ];
                        TimeSpan gapRemining = gap.End - seekMoment;

                        bool isTargetPeriod = false;
                        switch ( seekBoundaryMode )
                        {
                            case SeekBoundaryMode.Fill:
                                isTargetPeriod = gapRemining >= remaining;
//.........这里部分代码省略.........
开发者ID:jwg4,项目名称:date-difference,代码行数:101,代码来源:DateAdd.cs


示例20: GetDays

 // ----------------------------------------------------------------------
 public ITimePeriodCollection GetDays()
 {
     TimePeriodCollection days = new TimePeriodCollection();
     DateTime startDate = new DateTime( startYear, (int)startMonth, 1 );
     for ( int month = 0; month < monthCount; month++ )
     {
         DateTime monthStart = startDate.AddMonths( month );
         int daysOfMonth = TimeTool.GetDaysInMonth( monthStart.Year, monthStart.Month );
         for ( int day = 0; day < daysOfMonth; day++ )
         {
             days.Add( new Day( monthStart.AddDays( day ), Calendar ) );
         }
     }
     return days;
 }
开发者ID:jwg4,项目名称:date-difference,代码行数:16,代码来源:MonthTimeRange.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TimePeriod.TimeRange类代码示例发布时间:2022-05-26
下一篇:
C# IrrlichtNETCP.Vector3D类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap