Exemple #1
0
        public WorkdayCalculatorResult AdjustResultWithHolidays(WorkdayCalculatorResult calculatedResult,
                                                                FunctionArgument holidayArgument)
        {
            var startDate       = calculatedResult.StartDate;
            var endDate         = calculatedResult.EndDate;
            var direction       = calculatedResult.Direction;
            var workdaysCounted = calculatedResult.NumberOfWorkdays;
            var additionalDays  = new AdditionalHolidayDays(holidayArgument);

            foreach (var date in additionalDays.AdditionalDates)
            {
                if (direction == WorkdayCalculationDirection.Forward && (date < startDate || date > endDate))
                {
                    continue;
                }
                if (direction == WorkdayCalculationDirection.Backward && (date > startDate || date < endDate))
                {
                    continue;
                }
                if (_holidayWeekdays.IsHolidayWeekday(date))
                {
                    continue;
                }
                var tmpDate = _holidayWeekdays.GetNextWorkday(endDate, direction);
                while (additionalDays.AdditionalDates.Contains(tmpDate))
                {
                    tmpDate = _holidayWeekdays.GetNextWorkday(tmpDate, direction);
                }
                workdaysCounted++;
                endDate = tmpDate;
            }
            return(new WorkdayCalculatorResult(workdaysCounted, calculatedResult.StartDate, endDate, direction));
        }
Exemple #2
0
        public WorkdayCalculatorResult ReduceWorkdaysWithHolidays(WorkdayCalculatorResult calculatedResult,
                                                                  FunctionArgument holidayArgument)
        {
            var startDate      = calculatedResult.StartDate;
            var endDate        = calculatedResult.EndDate;
            var additionalDays = new AdditionalHolidayDays(holidayArgument);

            System.DateTime calcStartDate;
            System.DateTime calcEndDate;
            if (startDate < endDate)
            {
                calcStartDate = startDate;
                calcEndDate   = endDate;
            }
            else
            {
                calcStartDate = endDate;
                calcEndDate   = startDate;
            }
            var nAdditionalHolidayDays = additionalDays.AdditionalDates.Count(x => x >= calcStartDate && x <= calcEndDate && !_holidayWeekdays.IsHolidayWeekday(x));

            return(new WorkdayCalculatorResult(calculatedResult.NumberOfWorkdays - nAdditionalHolidayDays, startDate, endDate, calculatedResult.Direction));
        }
        public WorkdayCalculatorResult AdjustResultWithHolidays(WorkdayCalculatorResult calculatedResult,
            FunctionArgument holidayArgument)
        {
            var startDate = calculatedResult.StartDate;
            var endDate = calculatedResult.EndDate;
            var direction = calculatedResult.Direction;
            var workdaysCounted = calculatedResult.NumberOfWorkdays;
            var additionalDays = new AdditionalHolidayDays(holidayArgument);
            foreach (var date in additionalDays.AdditionalDates)
            {
                if (direction == WorkdayCalculationDirection.Forward && (date < startDate || date > endDate)) continue;
                if (direction == WorkdayCalculationDirection.Backward && (date > startDate || date < endDate)) continue;
                if (_holidayWeekdays.IsHolidayWeekday(date)) continue;
                var tmpDate = _holidayWeekdays.GetNextWorkday(endDate, direction);
                while (additionalDays.AdditionalDates.Contains(tmpDate))
                {
                    tmpDate = _holidayWeekdays.GetNextWorkday(tmpDate, direction);
                }
                workdaysCounted++;
                endDate = tmpDate;
            }

            return new WorkdayCalculatorResult(workdaysCounted, calculatedResult.StartDate, endDate, direction);
        }
 public WorkdayCalculatorResult ReduceWorkdaysWithHolidays(WorkdayCalculatorResult calculatedResult,
     FunctionArgument holidayArgument)
 {
     var startDate = calculatedResult.StartDate;
     var endDate = calculatedResult.EndDate;
     var additionalDays = new AdditionalHolidayDays(holidayArgument);
     System.DateTime calcStartDate;
     System.DateTime calcEndDate;
     if (startDate < endDate)
     {
         calcStartDate = startDate;
         calcEndDate = endDate;
     }
     else
     {
         calcStartDate = endDate;
         calcEndDate = startDate;
     }
     var nAdditionalHolidayDays = additionalDays.AdditionalDates.Count(x => x >= calcStartDate && x <= calcEndDate && !_holidayWeekdays.IsHolidayWeekday(x));
     return new WorkdayCalculatorResult(calculatedResult.NumberOfWorkdays - nAdditionalHolidayDays, startDate, endDate, calculatedResult.Direction);
 }