public void GetDurationsTest()
        {
            DateTime currentCalendarYear   = TimeTool.CurrentCalendarYear;
            DateTime previousCalendarMonth = currentCalendarYear.AddMonths(-1);
            DateTime previousCalendarYear  = currentCalendarYear.AddYears(-1);
            DateTime nextCalendarMonth     = currentCalendarYear.AddMonths(1);
            DateTime nextCalendarYear      = currentCalendarYear.AddYears(1);

            DateTimeSet dateTimeSet = new DateTimeSet
            {
                currentCalendarYear,
                nextCalendarYear,
                nextCalendarMonth,
                previousCalendarYear,
                previousCalendarMonth
            };

            IList <TimeSpan> durations1 = dateTimeSet.GetDurations(0, dateTimeSet.Count);

            Assert.AreEqual(durations1.Count, 4);
            Assert.AreEqual(durations1[0], previousCalendarMonth - previousCalendarYear);
            Assert.AreEqual(durations1[1], currentCalendarYear - previousCalendarMonth);
            Assert.AreEqual(durations1[2], nextCalendarMonth - currentCalendarYear);
            Assert.AreEqual(durations1[3], nextCalendarYear - nextCalendarMonth);

            IList <TimeSpan> durations2 = dateTimeSet.GetDurations(1, 2);

            Assert.AreEqual(durations2.Count, 2);
            Assert.AreEqual(durations2[0], currentCalendarYear - previousCalendarMonth);
            Assert.AreEqual(durations2[1], nextCalendarMonth - currentCalendarYear);

            IList <TimeSpan> durations3 = dateTimeSet.GetDurations(2, dateTimeSet.Count);

            Assert.AreEqual(durations3.Count, 2);
            Assert.AreEqual(durations3[0], nextCalendarMonth - currentCalendarYear);
            Assert.AreEqual(durations3[1], nextCalendarYear - nextCalendarMonth);
        }
Example #2
0
        public void GetDurationsTest()
        {
            DateTime currentCalendarYear   = Now.CalendarYear;
            DateTime previousCalendarMonth = currentCalendarYear.AddMonths(-1);
            DateTime previousCalendarYear  = currentCalendarYear.AddYears(-1);
            DateTime nextCalendarMonth     = currentCalendarYear.AddMonths(1);
            DateTime nextCalendarYear      = currentCalendarYear.AddYears(1);

            DateTimeSet dateTimeSet = new DateTimeSet();

            dateTimeSet.Add(currentCalendarYear);
            dateTimeSet.Add(nextCalendarYear);
            dateTimeSet.Add(nextCalendarMonth);
            dateTimeSet.Add(previousCalendarYear);
            dateTimeSet.Add(previousCalendarMonth);

            IList <TimeSpan> durations1 = dateTimeSet.GetDurations(0, dateTimeSet.Count);

            Assert.Equal(4, durations1.Count);
            Assert.Equal(durations1[0], previousCalendarMonth - previousCalendarYear);
            Assert.Equal(durations1[1], currentCalendarYear - previousCalendarMonth);
            Assert.Equal(durations1[2], nextCalendarMonth - currentCalendarYear);
            Assert.Equal(durations1[3], nextCalendarYear - nextCalendarMonth);

            IList <TimeSpan> durations2 = dateTimeSet.GetDurations(1, 2);

            Assert.Equal(2, durations2.Count);
            Assert.Equal(durations2[0], currentCalendarYear - previousCalendarMonth);
            Assert.Equal(durations2[1], nextCalendarMonth - currentCalendarYear);

            IList <TimeSpan> durations3 = dateTimeSet.GetDurations(2, dateTimeSet.Count);

            Assert.Equal(2, durations3.Count);
            Assert.Equal(durations3[0], nextCalendarMonth - currentCalendarYear);
            Assert.Equal(durations3[1], nextCalendarYear - nextCalendarMonth);
        }         // GetDurationsTest
Example #3
0
        public void GetDurationsTest() {
            DateTime currentCalendarYear = TimeTool.CurrentCalendarYear;
            DateTime previousCalendarMonth = currentCalendarYear.AddMonths(-1);
            DateTime previousCalendarYear = currentCalendarYear.AddYears(-1);
            DateTime nextCalendarMonth = currentCalendarYear.AddMonths(1);
            DateTime nextCalendarYear = currentCalendarYear.AddYears(1);

            DateTimeSet dateTimeSet = new DateTimeSet
                                      {
                                          currentCalendarYear,
                                          nextCalendarYear,
                                          nextCalendarMonth,
                                          previousCalendarYear,
                                          previousCalendarMonth
                                      };

            IList<TimeSpan> durations1 = dateTimeSet.GetDurations(0, dateTimeSet.Count);
            Assert.AreEqual(durations1.Count, 4);
            Assert.AreEqual(durations1[0], previousCalendarMonth - previousCalendarYear);
            Assert.AreEqual(durations1[1], currentCalendarYear - previousCalendarMonth);
            Assert.AreEqual(durations1[2], nextCalendarMonth - currentCalendarYear);
            Assert.AreEqual(durations1[3], nextCalendarYear - nextCalendarMonth);

            IList<TimeSpan> durations2 = dateTimeSet.GetDurations(1, 2);
            Assert.AreEqual(durations2.Count, 2);
            Assert.AreEqual(durations2[0], currentCalendarYear - previousCalendarMonth);
            Assert.AreEqual(durations2[1], nextCalendarMonth - currentCalendarYear);

            IList<TimeSpan> durations3 = dateTimeSet.GetDurations(2, dateTimeSet.Count);
            Assert.AreEqual(durations3.Count, 2);
            Assert.AreEqual(durations3[0], nextCalendarMonth - currentCalendarYear);
            Assert.AreEqual(durations3[1], nextCalendarYear - nextCalendarMonth);
        }
Example #4
0
        public void DateTimeSetSample()
        {
            DateTimeSet moments = new DateTimeSet();

            // --- add ---
            moments.Add( new DateTime( 2012, 8, 10, 18, 15, 0 ) );
            moments.Add( new DateTime( 2012, 8, 10, 15, 0, 0 ) );
            moments.Add( new DateTime( 2012, 8, 10, 13, 30, 0 ) );
            moments.Add( new DateTime( 2012, 8, 10, 15, 0, 0 ) ); // twice -> ignored
            Console.WriteLine( "DateTimeSet.Add(): " + moments );
            // > DateTimeSet.Add(): Count = 3; 10.08.2012 13:30:00 - 18:15:00 | 0.04:45
            for ( int i = 0; i < moments.Count; i++ )
            {
                Console.WriteLine( "Moment[{0:0}]: {1}", i, moments[ i ] );
            }
            // > Moment[0]: 10.08.2012 13:30:00
            // > Moment[1]: 10.08.2012 15:00:00
            // > Moment[2]: 10.08.2012 18:15:00

            // --- durations ---
            IList<TimeSpan> durations = moments.GetDurations( 0, moments.Count );
            Console.WriteLine( "DateTimeSet.GetDurations() " );
            for ( int i = 0; i < durations.Count; i++ )
            {
                Console.WriteLine( "Duration[{0:0}]: {1}", i, durations[ i ] );
            }
            // > Duration[0]: 01:30:00
            // > Duration[1]: 03:15:00
        }