AddWorkingWeekDays() public method

public AddWorkingWeekDays ( ) : void
return void
コード例 #1
0
 // ----------------------------------------------------------------------
 public DateTime AddBusinessDays2( DateTime startDate, int noOfBusinessDays )
 {
     CalendarDateAdd dateAdd = new CalendarDateAdd();
     dateAdd.AddWorkingWeekDays();
     DateTime? targetDate = dateAdd.Add( startDate.Date.AddTicks( 1 ), new TimeSpan( noOfBusinessDays, 0, 0, 0, 0 ) );
     return targetDate.HasValue ? targetDate.Value.Date : startDate.Date;
 }
コード例 #2
0
        // ----------------------------------------------------------------------
        public DateTime AddBusinessDays3( DateTime startDate, int noOfBusinessDays )
        {
            TimeCalendar timeCalendar = new TimeCalendar( new TimeCalendarConfig { EndOffset = TimeSpan.Zero } );
            CalendarDateAdd dateAdd = new CalendarDateAdd( timeCalendar );
            dateAdd.AddWorkingWeekDays();

            // Exclude holidays (simplified from the actual production code, here reduced to one hardcoded day)
            dateAdd.ExcludePeriods.Add( new Day( 2012, 6, 22, timeCalendar ) );
            DateTime? targetDate = dateAdd.Add( startDate.Date.AddTicks( 1 ), new TimeSpan( noOfBusinessDays, 0, 0, 0, 0 ) );
            return targetDate.HasValue ? targetDate.Value.Date : startDate.Date;
        }
コード例 #3
0
        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 ) );
        }
コード例 #4
0
        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 ) );
        }
コード例 #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
        }
コード例 #6
0
        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 ) );
        }
コード例 #7
0
        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 ) );
        }
コード例 #8
0
        public void AddWeekDaySample()
        {
            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 );
            Console.WriteLine( "AddWeekDaySample : {0}", calendarDateAdd.Add( start, new TimeSpan( 00, 0, 0 ) ) );
            // > AddWeekDaySample : 15.08.2011 09:00:00
            Console.WriteLine( "AddWeekDaySample : {0}", calendarDateAdd.Add( start, new TimeSpan( 07, 0, 0 ) ) );
            // > AddWeekDaySample : 16.08.2011 09:00:00
            Console.WriteLine( "AddWeekDaySample : {0}", calendarDateAdd.Add( start, new TimeSpan( 28, 0, 0 ) ) );
            // > AddWeekDaySample : 19.08.2011 09:00:00
            Console.WriteLine( "AddWeekDaySample : {0}", calendarDateAdd.Add( start, new TimeSpan( 31, 0, 0 ) ) );
            // > AddWeekDaySample : 19.08.2011 12:00:00
            Console.WriteLine( "AddWeekDaySample : {0}", calendarDateAdd.Add( start, new TimeSpan( 32, 0, 0 ) ) );
            // > AddWeekDaySample : 22.08.2011 09:00:00
        }