本文整理汇总了C#中Itenso.TimePeriod.TimePeriodCollection类的典型用法代码示例。如果您正苦于以下问题:C# TimePeriodCollection类的具体用法?C# TimePeriodCollection怎么用?C# TimePeriodCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimePeriodCollection类属于Itenso.TimePeriod命名空间,在下文中一共展示了TimePeriodCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 ) ) ) );
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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 ) );
}
示例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 );
}
示例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 );
}
示例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 ] );
}
示例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;
}