Example #1
0
        public void GivenTwoDates_ShouldCalculateBusinessDays(DateTime firstDate, DateTime secondDate, int expected)
        {
            var factory = new DayCounterFactory();

            var businessdaysBetweenDates = factory.CreateBusinessDayCounter().BusinessDaysBetweenTwoDates(firstDate, secondDate, Holidays);

            Assert.Equal(expected, businessdaysBetweenDates);
        }
Example #2
0
        public void GivenDayOfWeekInMonthInWeekRule_ShouldCalculateBusinessDays()
        {
            var rules = new List <PublicHolidayRule>
            {
                new DayOfWeekInMonthInWeekRule(6, WeekTypes.Week2, DayOfWeek.Monday) //Queens Birthday on the second Monday in June every year
            };

            var firstDate  = new DateTime(2013, 5, 31);
            var secondDate = new DateTime(2013, 6, 12);

            var factory = new DayCounterFactory();

            var businessdaysBetweenDates = factory.CreateEnhancedBusinessDayCounter().BusinessDaysBetweenTwoDates(firstDate, secondDate, rules);

            Assert.Equal(6, businessdaysBetweenDates);
        }
Example #3
0
        public void GivenDateRule_WhenHolidayIsInWeekends_ShouldHolidayMoveToMonday()
        {
            var rules = new List <PublicHolidayRule>
            {
                new DateRule(4, 25) //ANZAC Day
            };

            var firstDate  = new DateTime(2020, 4, 24);
            var secondDate = new DateTime(2020, 4, 29);

            var factory = new DayCounterFactory();

            var businessdaysBetweenDates = factory.CreateEnhancedBusinessDayCounter().BusinessDaysBetweenTwoDates(firstDate, secondDate, rules);

            Assert.Equal(1, businessdaysBetweenDates);
        }
Example #4
0
        static void Main(string[] args)
        {
            var counterFactory = new DayCounterFactory();

            Console.WriteLine("Task 1");
            TestWeekdaysBetweenTwoDates(counterFactory, new DateTime(2013, 10, 7), new DateTime(2013, 10, 9));
            TestWeekdaysBetweenTwoDates(counterFactory, new DateTime(2013, 10, 5), new DateTime(2013, 10, 14));
            TestWeekdaysBetweenTwoDates(counterFactory, new DateTime(2013, 10, 7), new DateTime(2014, 1, 1));
            TestWeekdaysBetweenTwoDates(counterFactory, new DateTime(2013, 10, 7), new DateTime(2013, 10, 5));

            Console.WriteLine("Task 2");
            var holidays = new List <DateTime>
            {
                new DateTime(2013, 12, 25),
                new DateTime(2013, 12, 26),
                new DateTime(2014, 1, 1),
            };

            TestBusinessdaysBetweenTwoDates(counterFactory, new DateTime(2013, 10, 7), new DateTime(2013, 10, 9), holidays);
            TestBusinessdaysBetweenTwoDates(counterFactory, new DateTime(2013, 12, 24), new DateTime(2013, 12, 27), holidays);
            TestBusinessdaysBetweenTwoDates(counterFactory, new DateTime(2013, 10, 7), new DateTime(2014, 1, 1), holidays);

            Console.WriteLine("Task 3");
            var rules = new List <PublicHolidayRule>
            {
                new DateRule(4, 25),                                                 //ANZAC Day
                new DateRule(12, 25),                                                //Christmas
                new DateRule(12, 26),                                                //Day after Christmas
                new DateRule(1, 1),                                                  //New Year
                new DayOfWeekInMonthInWeekRule(6, WeekTypes.Week2, DayOfWeek.Monday) //Queens Birthday on the second Monday in June every year
            };

            TestBusinessdaysBetweenTwoDatesWithComplexHolidayRules(counterFactory, new DateTime(2013, 10, 7), new DateTime(2013, 10, 9), rules);
            TestBusinessdaysBetweenTwoDatesWithComplexHolidayRules(counterFactory, new DateTime(2013, 12, 24), new DateTime(2013, 12, 27), rules);
            TestBusinessdaysBetweenTwoDatesWithComplexHolidayRules(counterFactory, new DateTime(2013, 10, 7), new DateTime(2014, 1, 1), rules);
            TestBusinessdaysBetweenTwoDatesWithComplexHolidayRules(counterFactory, new DateTime(2013, 6, 8), new DateTime(2013, 6, 12), rules);

            Console.ReadLine();
        }