public void TimeBlockSample() { // --- time block --- TimeBlock timeBlock = new TimeBlock( new DateTime( 2011, 2, 22, 11, 0, 0 ), new TimeSpan( 2, 0, 0 ) ); Console.WriteLine( "TimeBlock: " + timeBlock ); // > TimeBlock: 22.02.2011 11:00:00 - 13:00:00 | 02:00:00 // --- modification --- timeBlock.Start = new DateTime( 2011, 2, 22, 15, 0, 0 ); Console.WriteLine( "TimeBlock.Start: " + timeBlock ); // > TimeBlock.Start: 22.02.2011 15:00:00 - 17:00:00 | 02:00:00 timeBlock.Move( new TimeSpan( 1, 0, 0 ) ); Console.WriteLine( "TimeBlock.Move(1 hour): " + timeBlock ); // > TimeBlock.Move(1 hour): 22.02.2011 16:00:00 - 18:00:00 | 02:00:00 // --- previous/next --- Console.WriteLine( "TimeBlock.GetPreviousPeriod(): " + timeBlock.GetPreviousPeriod() ); // > TimeBlock.GetPreviousPeriod(): 22.02.2011 14:00:00 - 16:00:00 | 02:00:00 Console.WriteLine( "TimeBlock.GetNextPeriod(): " + timeBlock.GetNextPeriod() ); // > TimeBlock.GetNextPeriod(): 22.02.2011 18:00:00 - 20:00:00 | 02:00:00 Console.WriteLine( "TimeBlock.GetNextPeriod(+1 hour): " + timeBlock.GetNextPeriod( new TimeSpan( 1, 0, 0 ) ) ); // > TimeBlock.GetNextPeriod(+1 hour): 22.02.2011 19:00:00 - 21:00:00 | 02:00:00 Console.WriteLine( "TimeBlock.GetNextPeriod(-1 hour): " + timeBlock.GetNextPeriod( new TimeSpan( -1, 0, 0 ) ) ); // > TimeBlock.GetNextPeriod(-1 hour): 22.02.2011 17:00:00 - 19:00:00 | 02:00:00 }
public void GetNextPeriodTest() { TimeBlock readOnlyTimeBlock = new TimeBlock( start, duration, true ); Assert.IsTrue( readOnlyTimeBlock.GetNextPeriod().IsReadOnly ); TimeBlock timeBlock = new TimeBlock( start, duration ); Assert.AreEqual( timeBlock.Start, start ); Assert.AreEqual( timeBlock.End, end ); Assert.AreEqual( timeBlock.Duration, duration ); ITimeBlock nextTimeBlock = timeBlock.GetNextPeriod(); Assert.AreEqual( nextTimeBlock.Start, end ); Assert.AreEqual( nextTimeBlock.End, end.Add( duration ) ); Assert.AreEqual( nextTimeBlock.Duration, duration ); TimeSpan nextOffset = Duration.Hour; ITimeBlock nextOffsetTimeBlock = timeBlock.GetNextPeriod( nextOffset ); Assert.AreEqual( nextOffsetTimeBlock.Start, end.Add( nextOffset ) ); Assert.AreEqual( nextOffsetTimeBlock.End, end.Add( duration + nextOffset ) ); Assert.AreEqual( nextOffsetTimeBlock.Duration, duration ); }