Exemplo n.º 1
0
        // ----------------------------------------------------------------------
        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
        }         // TimeBlockSample
Exemplo n.º 2
0
        public void GetNextPeriodTest()
        {
            TimeBlock readOnlyTimeBlock = new TimeBlock(start, duration, true);

            Assert.True(readOnlyTimeBlock.GetNextPeriod().IsReadOnly);

            TimeBlock timeBlock = new TimeBlock(start, duration);

            Assert.Equal(timeBlock.Start, start);
            Assert.Equal(timeBlock.End, end);
            Assert.Equal(timeBlock.Duration, duration);

            ITimeBlock nextTimeBlock = timeBlock.GetNextPeriod();

            Assert.Equal(nextTimeBlock.Start, end);
            Assert.Equal(nextTimeBlock.End, end.Add(duration));
            Assert.Equal(nextTimeBlock.Duration, duration);

            TimeSpan   nextOffset          = Duration.Hour;
            ITimeBlock nextOffsetTimeBlock = timeBlock.GetNextPeriod(nextOffset);

            Assert.Equal(nextOffsetTimeBlock.Start, end.Add(nextOffset));
            Assert.Equal(nextOffsetTimeBlock.End, end.Add(duration + nextOffset));
            Assert.Equal(nextOffsetTimeBlock.Duration, duration);
        }         // GetNextPeriodTest