public void MoveTest() { TimeBlock timeBlockMoveZero = new TimeBlock( start, duration ); timeBlockMoveZero.Move( TimeSpan.Zero ); Assert.AreEqual( timeBlockMoveZero.Start, start ); Assert.AreEqual( timeBlockMoveZero.End, end ); Assert.AreEqual( timeBlockMoveZero.Duration, duration ); TimeBlock timeBlockMoveForward = new TimeBlock( start, duration ); TimeSpan forwardOffset = new TimeSpan( 2, 30, 15 ); timeBlockMoveForward.Move( forwardOffset ); Assert.AreEqual( timeBlockMoveForward.Start, start.Add( forwardOffset ) ); Assert.AreEqual( timeBlockMoveForward.End, end.Add( forwardOffset ) ); TimeBlock timeBlockMoveBackward = new TimeBlock( start, duration ); TimeSpan backwardOffset = new TimeSpan( -1, 10, 30 ); timeBlockMoveBackward.Move( backwardOffset ); Assert.AreEqual( timeBlockMoveBackward.Start, start.Add( backwardOffset ) ); Assert.AreEqual( timeBlockMoveBackward.End, end.Add( backwardOffset ) ); }
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 IsSamePeriodTest() { TimeBlock timeBlock1 = new TimeBlock( start, duration ); TimeBlock timeBlock2 = new TimeBlock( start, duration ); Assert.IsTrue( timeBlock1.IsSamePeriod( timeBlock1 ) ); Assert.IsTrue( timeBlock2.IsSamePeriod( timeBlock2 ) ); Assert.IsTrue( timeBlock1.IsSamePeriod( timeBlock2 ) ); Assert.IsTrue( timeBlock2.IsSamePeriod( timeBlock1 ) ); Assert.IsFalse( timeBlock1.IsSamePeriod( TimeBlock.Anytime ) ); Assert.IsFalse( timeBlock2.IsSamePeriod( TimeBlock.Anytime ) ); timeBlock1.Move( new TimeSpan( 1 ) ); Assert.IsFalse( timeBlock1.IsSamePeriod( timeBlock2 ) ); Assert.IsFalse( timeBlock2.IsSamePeriod( timeBlock1 ) ); timeBlock1.Move( new TimeSpan( -1 ) ); Assert.IsTrue( timeBlock1.IsSamePeriod( timeBlock2 ) ); Assert.IsTrue( timeBlock2.IsSamePeriod( timeBlock1 ) ); }