Пример #1
0
        private static int countExcludedItems(DateTime startDate, DateTime endDate, TimeframeSymbol timeframe)
        {
            int weekends = 0;
            int christmas = 0;
            int newYears = 0;
            int sign = (startDate.CompareTo(endDate) < 0 ? 1 : -1);

            weekends = countWeekendItems(startDate, endDate, timeframe);
            newYears = sign * startDate.countNewYearBreaks(endDate, false) * (dayUnitsForTimeframe(timeframe) + getTimeframeHolidayInactiveUnits(timeframe));
            christmas = sign * startDate.countChristmas(endDate, false) * (dayUnitsForTimeframe(timeframe) + getTimeframeHolidayInactiveUnits(timeframe));

            return (weekends + christmas + newYears);
        }
Пример #2
0
        public void countNewYearBreaks_if_dates_in_the_same_year_positive_difference_zero_is_returned()
        {
            DateTime baseDate = new DateTime(2016, 1, 4);
            DateTime comparedDate = new DateTime(2016, 1, 10);

            Assert.AreEqual(0, baseDate.countNewYearBreaks(comparedDate, true));
        }
Пример #3
0
        private static DateTime addTimeUnits_days(DateTime date, int units)
        {
            int remainder = units % 5;
            int newWeekDay = (int)date.DayOfWeek + remainder;
            bool breakWeek = newWeekDay > 5 || newWeekDay <= 0;
            int daysToAdd = (units / 5) * 7 + remainder + Math.Sign(units) * (breakWeek ? 2 : 0);
            DateTime newDate = date.AddDays(daysToAdd);

            //Include year breaks.
            int yearBreaks = date.countNewYearBreaks(newDate, false);
            int christmas = date.countChristmas(newDate, false);
            if (yearBreaks + christmas > 0)
            {
                newDate = addTimeUnits_days(newDate, Math.Sign(units) * (yearBreaks + christmas));
            }

            //Check if the result date is not New Year nor Christmas.
            while (newDate.DayOfWeek == DayOfWeek.Sunday || newDate.DayOfWeek == DayOfWeek.Saturday || newDate.DayOfYear == 1 || newDate.IsChristmas())
            {
                int sign = Math.Sign(units);
                newDate = newDate.AddDays(sign);
            }

            return newDate;
        }
Пример #4
0
        public void countNewYearBreaks_correct_value_is_returned_for_positive_difference_including_weekends()
        {
            DateTime baseDate = new DateTime(2010, 12, 30);
            DateTime comparedDate = new DateTime(2016, 1, 4);

            Assert.AreEqual(6, baseDate.countNewYearBreaks(comparedDate, true));
        }
Пример #5
0
        public void countNewYearBreaks_correct_value_is_returned_for_date_from_previous_year_NY_at_week_including_weekends()
        {
            DateTime baseDate = new DateTime(2016, 1, 4);
            DateTime comparedDate = new DateTime(2015, 12, 30);

            Assert.AreEqual(1, baseDate.countNewYearBreaks(comparedDate, true));
        }
Пример #6
0
        public void countNewYearBreaks_correct_value_is_returned_for_date_from_previous_year_NY_at_weekend_excluding_weekends()
        {
            DateTime baseDate = new DateTime(2011, 1, 3);
            DateTime comparedDate = new DateTime(2010, 12, 30);

            Assert.AreEqual(0, baseDate.countNewYearBreaks(comparedDate, false));
        }
Пример #7
0
        public void countNewYearBreaks_both_dates_are_weekend_newYears_weekend_included()
        {
            DateTime baseDate = new DateTime(2012, 1, 1);
            DateTime comparedDate = new DateTime(2017, 1, 1);

            Assert.AreEqual(5, baseDate.countNewYearBreaks(comparedDate, true));
        }
Пример #8
0
        public void countNewYearBreaks_both_dates_are_newYears_one_of_them_weekend_weekends_included()
        {
            DateTime baseDate = new DateTime(2016, 1, 1);
            DateTime comparedDate = new DateTime(2017, 1, 1);

            Assert.AreEqual(1, baseDate.countNewYearBreaks(comparedDate, true));
        }