本文整理汇总了C#中Itenso.TimePeriod.TimeRange类的典型用法代码示例。如果您正苦于以下问题:C# TimeRange类的具体用法?C# TimeRange怎么用?C# TimeRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimeRange类属于Itenso.TimePeriod命名空间,在下文中一共展示了TimeRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Availabilities
public JsonResult Availabilities(int hotelId, IEnumerable<int> roomTypeIds, DateTime start, DateTime end, DateTime? startTime, DateTime? endTime, IEnumerable<Query> queries)
{
var startDT = start.MergeTime(startTime);
var endDT = end.MergeTime(endTime);
var manager = this.GetManagerFor<IRoomBookingManager>();
var results = manager.Search(hotelId, roomTypeIds, startDT, endDT).ToList();
var periods = new TimeRange(startDT, endDT, true);
var collector = new CalendarPeriodCollector(new CalendarPeriodCollectorFilter(), periods);
collector.CollectDays();
var days = collector.Periods.Select(d => d.Start).ToList();
days.Add(endDT);
days.Insert(0, startDT);
var tManager = this.GetManagerFor<IRoomTypeManager>();
var roomTypes = tManager.GetByIds(roomTypeIds).ToList();
var resultDTOs = results.Select(t => new RoomBookingDTO(queries, t));
var json = new AvailabilityResultDTO
{
DTSlots = days,
RoomTypes = roomTypes.Select(t => new RoomTypeDTO
{
Id = t.Id,
Name = t.Name,
Rooms = t.Rooms.Where(r => r.HotelId == hotelId).Select(r => new RoomDTO(r)).ToList()
}).ToList(),
Bookings = resultDTOs
};
return Json(json);
}
示例2: MomentTest
public void MomentTest()
{
TimeRange period = new TimeRange( new DateTime( 2011, 3, 1 ), new DateTime( 2011, 3, 1 ) );
TimePeriodCombiner<TimeRange> periodCombiner = new TimePeriodCombiner<TimeRange>();
ITimePeriodCollection periods = periodCombiner.CombinePeriods( new TimePeriodCollection { period } );
Assert.AreEqual( periods.Count, 1 );
Assert.IsTrue( periods[ 0 ].IsSamePeriod( period ) );
}
示例3: MomentTest
public void MomentTest()
{
TimeRange period1 = new TimeRange( new DateTime( 2011, 3, 1 ), new DateTime( 2011, 3, 10 ) );
TimeRange period2 = new TimeRange( new DateTime( 2011, 3, 5 ), new DateTime( 2011, 3, 05 ) );
TimePeriodIntersector<TimeRange> periodIntersector = new TimePeriodIntersector<TimeRange>();
ITimePeriodCollection periods = periodIntersector.IntersectPeriods( new TimePeriodCollection { period1, period2 } );
Assert.AreEqual( periods.Count, 0 );
}
示例4: MomentTest
public void MomentTest()
{
TimeRange period1 = new TimeRange( new DateTime( 2011, 3, 1 ), new DateTime( 2011, 3, 10 ) );
TimeRange period2 = new TimeRange( new DateTime( 2011, 3, 5 ), new DateTime( 2011, 3, 05 ) );
TimePeriodSubtractor<TimeRange> periodSubtractor = new TimePeriodSubtractor<TimeRange>();
ITimePeriodCollection periods = periodSubtractor.SubtractPeriods( new TimePeriodCollection { period1 }, new TimePeriodCollection { period2 } );
Assert.AreEqual( periods.Count, 1 );
Assert.IsTrue( periods[ 0 ].IsSamePeriod( period1 ) );
}
示例5: CombineTest
public void CombineTest()
{
TimeRange period1 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 05 ) );
TimeRange period2 = new TimeRange( new DateTime( 2011, 3, 05 ), new DateTime( 2011, 3, 10 ) );
TimePeriodSubtractor<TimeRange> periodSubtractor = new TimePeriodSubtractor<TimeRange>();
ITimePeriodCollection periods = periodSubtractor.SubtractPeriods( new TimePeriodCollection { period1, period2 }, new TimePeriodCollection() );
Assert.AreEqual( periods.Count, 1 );
Assert.IsTrue( periods[ 0 ].IsSamePeriod( new TimeRange( period1.Start, period2.End ) ) );
}
示例6: CopyConstructorTest
public void CopyConstructorTest()
{
TimeRange source = new TimeRange( start, start.AddHours( 1 ), true );
TimeRange copy = new TimeRange( source );
Assert.AreEqual( source.Start, copy.Start );
Assert.AreEqual( source.End, copy.End );
Assert.AreEqual( source.IsReadOnly, copy.IsReadOnly );
Assert.AreEqual( source, copy );
}
示例7: AddTimeRangeTest
public void AddTimeRangeTest()
{
DateTime now = ClockProxy.Clock.Now;
SchoolDay schoolDay = new SchoolDay( now );
TimePeriodChain timePeriods = new TimePeriodChain( schoolDay );
TimeRange timeRange = new TimeRange( schoolDay.Lesson1.Start, schoolDay.Lesson1.End );
timePeriods.Add( timeRange );
Assert.AreEqual( timePeriods.Last, timeRange );
}
示例8: AllExcludedTest
public void AllExcludedTest()
{
DateTime test = new DateTime( 2011, 4, 12 );
TimeRange timeRange = new TimeRange( new DateTime( 2011, 4, 10 ), new DateTime( 2011, 4, 20 ) );
DateAdd dateAdd = new DateAdd();
dateAdd.IncludePeriods.Add( timeRange );
dateAdd.ExcludePeriods.Add( timeRange );
Assert.IsNull( dateAdd.Add( test, TimeSpan.Zero ) );
}
示例9: MultipeTouchingIntersection1Test
public void MultipeTouchingIntersection1Test()
{
TimeRange period1 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 10 ) );
TimeRange period2 = new TimeRange( new DateTime( 2011, 3, 05 ), new DateTime( 2011, 3, 20 ) );
TimeRange period3 = new TimeRange( new DateTime( 2011, 3, 15 ), new DateTime( 2011, 3, 25 ) );
TimePeriodIntersector<TimeRange> periodIntersector = new TimePeriodIntersector<TimeRange>();
ITimePeriodCollection periods = periodIntersector.IntersectPeriods( new TimePeriodCollection { period1, period2, period3 } );
Assert.AreEqual( periods.Count, 2 );
Assert.IsTrue( periods[ 0 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 05 ), new DateTime( 2011, 3, 10 ) ) ) );
Assert.IsTrue( periods[ 1 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 15 ), new DateTime( 2011, 3, 20 ) ) ) );
}
示例10: IntersectionPeriodsTest
public void IntersectionPeriodsTest()
{
TimeRange period1 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 4, 01 ) );
TimeRange period2 = new TimeRange( new DateTime( 2011, 3, 05 ), new DateTime( 2011, 3, 10 ) );
TimeRange period3 = new TimeRange( new DateTime( 2011, 3, 20 ), new DateTime( 2011, 3, 25 ) );
TimePeriodSubtractor<TimeRange> periodSubtractor = new TimePeriodSubtractor<TimeRange>();
ITimePeriodCollection periods = periodSubtractor.SubtractPeriods( new TimePeriodCollection { period1 }, new TimePeriodCollection { period2, period3 } );
Assert.AreEqual( periods.Count, 3 );
Assert.IsTrue( periods[ 0 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 05 ) ) ) );
Assert.IsTrue( periods[ 1 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 10 ), new DateTime( 2011, 3, 20 ) ) ) );
Assert.IsTrue( periods[ 2 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 25 ), new DateTime( 2011, 4, 01 ) ) ) );
}
示例11: Pattern3Test
public void Pattern3Test()
{
TimeRange period1 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 05 ) );
TimeRange period2 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 10 ) );
TimeRange period3 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 15 ) );
TimeRange period4 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 20 ) );
TimeRange period5 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 25 ) );
TimePeriodCombiner<TimeRange> periodCombiner = new TimePeriodCombiner<TimeRange>();
ITimePeriodCollection periods = periodCombiner.CombinePeriods( new TimePeriodCollection { period1, period2, period3, period4, period5 } );
Assert.AreEqual( periods.Count, 1 );
Assert.IsTrue( periods[ 0 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 1 ), new DateTime( 2011, 3, 25 ) ) ) );
}
示例12: MultipeTouchingIntersection2Test
public void MultipeTouchingIntersection2Test()
{
TimeRange period1 = new TimeRange( new DateTime( 2011, 3, 01 ), new DateTime( 2011, 3, 10 ) );
TimeRange period2 = new TimeRange( new DateTime( 2011, 3, 04 ), new DateTime( 2011, 3, 10 ) );
TimeRange period3 = new TimeRange( new DateTime( 2011, 3, 06 ), new DateTime( 2011, 3, 10 ) );
TimeRange period4 = new TimeRange( new DateTime( 2011, 3, 10 ), new DateTime( 2011, 3, 14 ) );
TimeRange period5 = new TimeRange( new DateTime( 2011, 3, 10 ), new DateTime( 2011, 3, 16 ) );
TimeRange period6 = new TimeRange( new DateTime( 2011, 3, 10 ), new DateTime( 2011, 3, 20 ) );
TimePeriodIntersector<TimeRange> periodIntersector = new TimePeriodIntersector<TimeRange>();
ITimePeriodCollection periods = periodIntersector.IntersectPeriods( new TimePeriodCollection { period1, period2, period3, period4, period5, period6 } );
Assert.AreEqual( periods.Count, 1 );
Assert.IsTrue( periods[ 0 ].IsSamePeriod( new TimeRange( new DateTime( 2011, 3, 04 ), new DateTime( 2011, 3, 16 ) ) ) );
}
示例13: ExcludeSplitTest
public void ExcludeSplitTest()
{
DateTime test = new DateTime( 2011, 4, 12 );
TimeRange timeRange1 = new TimeRange( new DateTime( 2011, 4, 15 ), new DateTime( 2011, 4, 20 ) );
TimeRange timeRange2 = new TimeRange( new DateTime( 2011, 4, 22 ), new DateTime( 2011, 4, 25 ) );
DateAdd dateAdd = new DateAdd();
dateAdd.ExcludePeriods.Add( timeRange1 );
dateAdd.ExcludePeriods.Add( timeRange2 );
Assert.AreEqual( dateAdd.Add( test, TimeSpan.Zero ), test );
Assert.AreEqual( dateAdd.Add( test, new TimeSpan( 2, 0, 0, 0 ) ), test.Add( new TimeSpan( 2, 0, 0, 0 ) ) );
Assert.AreEqual( dateAdd.Add( test, new TimeSpan( 3, 0, 0, 0 ) ), timeRange1.End );
Assert.AreEqual( dateAdd.Add( test, new TimeSpan( 4, 0, 0, 0 ) ), timeRange1.End.Add( new TimeSpan( 1, 0, 0, 0 ) ) );
Assert.AreEqual( dateAdd.Add( test, new TimeSpan( 5, 0, 0, 0 ) ), timeRange2.End );
Assert.AreEqual( dateAdd.Add( test, new TimeSpan( 7, 0, 0, 0 ) ), timeRange2.End.Add( new TimeSpan( 2, 0, 0, 0 ) ) );
}
示例14: TimeRangePeriodRelationTestData
// ----------------------------------------------------------------------
public TimeRangePeriodRelationTestData( DateTime start, DateTime end, TimeSpan offset )
{
if ( offset <= TimeSpan.Zero )
{
throw new ArgumentOutOfRangeException( "offset" );
}
Reference = new TimeRange( start, end, true );
DateTime beforeEnd = start.Subtract( offset );
DateTime beforeStart = beforeEnd.Subtract( Reference.Duration );
DateTime insideStart = start.Add( offset );
DateTime insideEnd = end.Subtract( offset );
DateTime afterStart = end.Add( offset );
DateTime afterEnd = afterStart.Add( Reference.Duration );
After = new TimeRange( beforeStart, beforeEnd, true );
StartTouching = new TimeRange( beforeStart, start, true );
StartInside = new TimeRange( beforeStart, insideStart, true );
InsideStartTouching = new TimeRange( start, afterStart, true );
EnclosingStartTouching = new TimeRange( start, insideEnd, true );
Enclosing = new TimeRange( insideStart, insideEnd, true );
EnclosingEndTouching = new TimeRange( insideStart, end, true );
ExactMatch = new TimeRange( start, end, true );
Inside = new TimeRange( beforeStart, afterEnd, true );
InsideEndTouching = new TimeRange( beforeStart, end, true );
EndInside = new TimeRange( insideEnd, afterEnd, true );
EndTouching = new TimeRange( end, afterEnd, true );
Before = new TimeRange( afterStart, afterEnd, true );
allPeriods.Add( Reference );
allPeriods.Add( After );
allPeriods.Add( StartTouching );
allPeriods.Add( StartInside );
allPeriods.Add( InsideStartTouching );
allPeriods.Add( EnclosingStartTouching );
allPeriods.Add( Enclosing );
allPeriods.Add( EnclosingEndTouching );
allPeriods.Add( ExactMatch );
allPeriods.Add( Inside );
allPeriods.Add( InsideEndTouching );
allPeriods.Add( EndInside );
allPeriods.Add( EndTouching );
allPeriods.Add( Before );
}
示例15: CopyTest
public void CopyTest()
{
TimeRange readOnlyTimeRange = new TimeRange( start, end );
Assert.AreEqual( readOnlyTimeRange.Copy( TimeSpan.Zero ), readOnlyTimeRange );
TimeRange timeRange = new TimeRange( start, end );
Assert.AreEqual( timeRange.Start, start );
Assert.AreEqual( timeRange.End, end );
ITimeRange noMoveTimeRange = timeRange.Copy( TimeSpan.Zero );
Assert.AreEqual( noMoveTimeRange.Start, start );
Assert.AreEqual( noMoveTimeRange.End, end );
Assert.AreEqual( noMoveTimeRange.Duration, duration );
TimeSpan forwardOffset = new TimeSpan( 2, 30, 15 );
ITimeRange forwardTimeRange = timeRange.Copy( forwardOffset );
Assert.AreEqual( forwardTimeRange.Start, start.Add( forwardOffset ) );
Assert.AreEqual( forwardTimeRange.End, end.Add( forwardOffset ) );
TimeSpan backwardOffset = new TimeSpan( -1, 10, 30 );
ITimeRange backwardTimeRange = timeRange.Copy( backwardOffset );
Assert.AreEqual( backwardTimeRange.Start, start.Add( backwardOffset ) );
Assert.AreEqual( backwardTimeRange.End, end.Add( backwardOffset ) );
}