public void EmptyStartWeekTest()
        {
            CalendarDateAdd calendarDateAdd = new CalendarDateAdd();

            // weekdays
            calendarDateAdd.AddWorkingWeekDays();
            //Start on a Saturday
            DateTime start  = new DateTime(2011, 4, 2, 13, 0, 0);
            TimeSpan offset = new TimeSpan(20, 0, 0);               // 20 hours

            Assert.AreEqual(calendarDateAdd.Add(start, offset), new DateTime(2011, 4, 4, 20, 00, 0));
        }         // EmptyStartWeekTest
        public void CalendarDateAdd3Test()
        {
            CalendarDateAdd calendarDateAdd = new CalendarDateAdd();

            calendarDateAdd.AddWorkingWeekDays();
            calendarDateAdd.ExcludePeriods.Add(new Day(2011, 4, 4, calendarDateAdd.Calendar));
            calendarDateAdd.WorkingHours.Add(new HourRange(new Time(8, 30), new Time(12)));
            calendarDateAdd.WorkingHours.Add(new HourRange(new Time(13, 30), new Time(18)));

            DateTime start = new DateTime(2011, 4, 1, 9, 0, 0);

            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(03, 0, 0)), new DateTime(2011, 4, 1, 13, 30, 0));
            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(04, 0, 0)), new DateTime(2011, 4, 1, 14, 30, 0));
            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(08, 0, 0)), new DateTime(2011, 4, 5, 09, 00, 0));
        }         // CalendarDateAdd3Test
        public void CalendarDateAdd1Test()
        {
            TimeCalendar timeCalendar = new TimeCalendar(new TimeCalendarConfig
            {
                Culture   = new CultureInfo("en-AU"),
                EndOffset = TimeSpan.Zero
            });

            CalendarDateAdd calendarDateAdd = new CalendarDateAdd(timeCalendar);

            calendarDateAdd.AddWorkingWeekDays();
            calendarDateAdd.ExcludePeriods.Add(new Day(2011, 4, 4, calendarDateAdd.Calendar));
            calendarDateAdd.WorkingHours.Add(new HourRange(8, 18));

            DateTime start = new DateTime(2011, 4, 1, 9, 0, 0);

            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(22, 0, 0)), new DateTime(2011, 4, 6, 11, 0, 0));
            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(29, 0, 0)), new DateTime(2011, 4, 7, 8, 0, 0));
        }         // CalendarDateAdd1Test
        public void WorkingDayHoursTest()
        {
            CalendarDateAdd calendarDateAdd = new CalendarDateAdd();

            calendarDateAdd.AddWorkingWeekDays();

            calendarDateAdd.WorkingDayHours.Add(new DayHourRange(DayOfWeek.Monday, 09, 16));
            calendarDateAdd.WorkingDayHours.Add(new DayHourRange(DayOfWeek.Tuesday, 09, 16));
            calendarDateAdd.WorkingDayHours.Add(new DayHourRange(DayOfWeek.Wednesday, 09, 16));
            calendarDateAdd.WorkingDayHours.Add(new DayHourRange(DayOfWeek.Thursday, 09, 16));
            calendarDateAdd.WorkingDayHours.Add(new DayHourRange(DayOfWeek.Friday, 09, 13));

            DateTime start = new DateTime(2011, 08, 15);

            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(00, 0, 0)), new DateTime(2011, 8, 15, 09, 0, 0));
            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(07, 0, 0)), new DateTime(2011, 8, 16, 09, 0, 0));
            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(28, 0, 0)), new DateTime(2011, 8, 19, 09, 0, 0));
            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(31, 0, 0)), new DateTime(2011, 8, 19, 12, 0, 0));
            Assert.AreEqual(calendarDateAdd.Add(start, new TimeSpan(32, 0, 0)), new DateTime(2011, 8, 22, 09, 0, 0));
        } // WorkingDayHoursTest
Example #5
0
        // ----------------------------------------------------------------------
        public void CalendarDateAddSample()
        {
            CalendarDateAdd calendarDateAdd = new CalendarDateAdd();

            // weekdays
            calendarDateAdd.AddWorkingWeekDays();
            // holidays
            calendarDateAdd.ExcludePeriods.Add(new Day(2011, 4, 5, calendarDateAdd.Calendar));
            // working hours
            calendarDateAdd.WorkingHours.Add(new HourRange(new Time(08, 30), new Time(12)));
            calendarDateAdd.WorkingHours.Add(new HourRange(new Time(13, 30), new Time(18)));

            DateTime start  = new DateTime(2011, 4, 1, 9, 0, 0);
            TimeSpan offset = new TimeSpan(22, 0, 0);               // 22 hours

            DateTime?end = calendarDateAdd.Add(start, offset);

            Console.WriteLine("start: {0}", start);
            // > start: 01.04.2011 09:00:00
            Console.WriteLine("offset: {0}", offset);
            // > offset: 22:00:00
            Console.WriteLine("end: {0}", end);
            // > end: 06.04.2011 16:30:00
        }         // CalendarDateAddSample