コード例 #1
0
        public void TestCountBusinessDaysUsingRules()
        {
            var counter = new BusinessDayCounter();

            var holidayRules = new List <IHolidayRule>()
            {
                new AlwaysOnSameDayRule
                {
                    Day   = 25,
                    Month = 4
                },
                new AlwaysOnSameDayExceptOnWeekendsRule
                {
                    Day   = 1,
                    Month = 1
                },
                new CertainOccurenceOfCertainDayInAMonthRule
                {
                    DayOfWeek   = DayOfWeek.Monday,
                    Month       = 6,
                    WeekOfMonth = 2
                },
                new AlwaysOnSameDayRule
                {
                    Day   = 25,
                    Month = 12
                },
                new AlwaysOnSameDayRule
                {
                    Day   = 26,
                    Month = 12
                },
            };

            var beginDate = new DateTime(2013, 10, 7);
            var endDate   = new DateTime(2013, 10, 9);

            Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidayRules), 1);

            beginDate = new DateTime(2013, 12, 24);
            endDate   = new DateTime(2013, 12, 27);
            Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidayRules), 0);

            beginDate = new DateTime(2013, 10, 7);
            endDate   = new DateTime(2014, 1, 1);
            Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidayRules), 59);
        }
コード例 #2
0
        public void TestCountBusinessDays()
        {
            var counter = new BusinessDayCounter();

            var holidays = new List <DateTime>
            {
                new DateTime(2013, 12, 25),
                new DateTime(2013, 12, 26),
                new DateTime(2014, 1, 1)
            };

            var beginDate = new DateTime(2013, 10, 7);
            var endDate   = new DateTime(2013, 10, 9);

            Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidays), 1);

            beginDate = new DateTime(2013, 12, 24);
            endDate   = new DateTime(2013, 12, 27);
            Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidays), 0);

            beginDate = new DateTime(2013, 10, 7);
            endDate   = new DateTime(2014, 1, 1);
            Assert.AreEqual(counter.BusinessBetweenTwoDates(beginDate, endDate, holidays), 59);
        }