本文整理汇总了C#中Itenso.TimePeriod.TimeRange.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# TimeRange.Copy方法的具体用法?C# TimeRange.Copy怎么用?C# TimeRange.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Itenso.TimePeriod.TimeRange
的用法示例。
在下文中一共展示了TimeRange.Copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 ) );
}
示例2: OverlapPeriodsTest
public void OverlapPeriodsTest()
{
DateTime now = ClockProxy.Clock.Now;
TimeRange timeRange1 = new TimeRange( new DateTime( now.Year, now.Month, 8 ), new DateTime( now.Year, now.Month, 18 ) );
TimeRange timeRange2 = new TimeRange( new DateTime( now.Year, now.Month, 10 ), new DateTime( now.Year, now.Month, 11 ) );
TimeRange timeRange3 = new TimeRange( new DateTime( now.Year, now.Month, 13 ), new DateTime( now.Year, now.Month, 15 ) );
TimeRange timeRange4 = new TimeRange( new DateTime( now.Year, now.Month, 9 ), new DateTime( now.Year, now.Month, 13 ) );
TimeRange timeRange5 = new TimeRange( new DateTime( now.Year, now.Month, 15 ), new DateTime( now.Year, now.Month, 17 ) );
TimePeriodCollection timePeriods = new TimePeriodCollection();
timePeriods.Add( timeRange1 );
timePeriods.Add( timeRange2 );
timePeriods.Add( timeRange3 );
timePeriods.Add( timeRange4 );
timePeriods.Add( timeRange5 );
Assert.AreEqual( timePeriods.OverlapPeriods( timeRange1 ).Count, 5 );
Assert.AreEqual( timePeriods.OverlapPeriods( timeRange2 ).Count, 3 );
Assert.AreEqual( timePeriods.OverlapPeriods( timeRange3 ).Count, 2 );
Assert.AreEqual( timePeriods.OverlapPeriods( timeRange4 ).Count, 3 );
Assert.AreEqual( timePeriods.OverlapPeriods( timeRange5 ).Count, 2 );
ITimeRange test1 = timeRange1.Copy( new TimeSpan( 100, 0, 0, 0 ).Negate() );
ITimePeriodCollection insidePeriods1 = timePeriods.OverlapPeriods( test1 );
Assert.AreEqual( insidePeriods1.Count, 0 );
ITimeRange test2 = timeRange1.Copy( new TimeSpan( 100, 0, 0, 0 ) );
ITimePeriodCollection insidePeriods2 = timePeriods.OverlapPeriods( test2 );
Assert.AreEqual( insidePeriods2.Count, 0 );
TimeRange test3 = new TimeRange( new DateTime( now.Year, now.Month, 9 ), new DateTime( now.Year, now.Month, 11 ) );
ITimePeriodCollection insidePeriods3 = timePeriods.OverlapPeriods( test3 );
Assert.AreEqual( insidePeriods3.Count, 3 );
TimeRange test4 = new TimeRange( new DateTime( now.Year, now.Month, 14 ), new DateTime( now.Year, now.Month, 17 ) );
ITimePeriodCollection insidePeriods4 = timePeriods.OverlapPeriods( test4 );
Assert.AreEqual( insidePeriods4.Count, 3 );
}