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 GetPreviousPeriodTest() { TimeBlock readOnlyTimeBlock = new TimeBlock( start, duration, true ); Assert.IsTrue( readOnlyTimeBlock.GetPreviousPeriod().IsReadOnly ); TimeBlock timeBlock = new TimeBlock( start, duration ); Assert.AreEqual( timeBlock.Start, start ); Assert.AreEqual( timeBlock.End, end ); Assert.AreEqual( timeBlock.Duration, duration ); ITimeBlock previousTimeBlock = timeBlock.GetPreviousPeriod(); Assert.AreEqual( previousTimeBlock.Start, start.Subtract( duration ) ); Assert.AreEqual( previousTimeBlock.End, start ); Assert.AreEqual( previousTimeBlock.Duration, duration ); TimeSpan previousOffset = Duration.Hour.Negate(); ITimeBlock previousOffsetTimeBlock = timeBlock.GetPreviousPeriod( previousOffset ); Assert.AreEqual( previousOffsetTimeBlock.Start, start.Subtract( duration ).Add( previousOffset ) ); Assert.AreEqual( previousOffsetTimeBlock.End, end.Subtract( duration ) .Add( previousOffset ) ); Assert.AreEqual( previousOffsetTimeBlock.Duration, duration ); }