本文整理汇总了C#中Itenso.TimePeriod.TimePeriodCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# TimePeriodCollection.Add方法的具体用法?C# TimePeriodCollection.Add怎么用?C# TimePeriodCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Itenso.TimePeriod.TimePeriodCollection
的用法示例。
在下文中一共展示了TimePeriodCollection.Add方法的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: 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 ) );
}
示例3: 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 );
}
示例4: 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 ] );
}
示例5: GetYears
// ----------------------------------------------------------------------
public ITimePeriodCollection GetYears()
{
TimePeriodCollection years = new TimePeriodCollection();
for ( int i = 0; i < YearCount; i++ )
{
years.Add( new Year( StartYear + i, Calendar ) );
}
return years;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: IsAnytimeTest
public void IsAnytimeTest()
{
DateTime now = ClockProxy.Clock.Now;
TimePeriodCollection timePeriods = new TimePeriodCollection();
Assert.IsTrue( timePeriods.IsAnytime );
timePeriods.Add( TimeRange.Anytime );
Assert.IsTrue( timePeriods.IsAnytime );
timePeriods.Clear();
Assert.IsTrue( timePeriods.IsAnytime );
timePeriods.Add( new TimeRange( TimeSpec.MinPeriodDate, now ) );
Assert.IsFalse( timePeriods.IsAnytime );
timePeriods.Add( new TimeRange( now, TimeSpec.MaxPeriodDate ) );
Assert.IsTrue( timePeriods.IsAnytime );
timePeriods.Clear();
Assert.IsTrue( timePeriods.IsAnytime );
}