Пример #1
0
        /**
         * Evaluate for NETWORKDAYS. Given two dates and a optional date or interval of holidays, determines how many working days are there
         * between those dates.
         *
         * @return {@link ValueEval} for the number of days between two dates.
         */

        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
        {
            if (args.Length < 2 || args.Length > 3)
            {
                return(ErrorEval.VALUE_INVALID);
            }

            int srcCellRow = ec.RowIndex;
            int srcCellCol = ec.ColumnIndex;

            double start, end;

            double[] holidays;
            try
            {
                start = evaluator.EvaluateDateArg(args[0], srcCellRow, srcCellCol);
                end   = evaluator.EvaluateDateArg(args[1], srcCellRow, srcCellCol);
                if (start > end)
                {
                    return(ErrorEval.NAME_INVALID);
                }
                ValueEval holidaysCell = args.Length == 3 ? args[2] : null;
                holidays = evaluator.EvaluateDatesArg(holidaysCell, srcCellRow, srcCellCol);
                return(new NumberEval(WorkdayCalculator.instance.CalculateWorkdays(start, end, holidays)));
            }
            catch (EvaluationException)
            {
                return(ErrorEval.VALUE_INVALID);
            }
        }
Пример #2
0
        /**
         * Evaluate for WORKDAY. Given a date, a number of days and a optional date or interval of holidays, determines which date it is past
         * number of parametrized workdays.
         *
         * @return {@link ValueEval} with date as its value.
         */

        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
        {
            if (args.Length < 2 || args.Length > 3)
            {
                return(ErrorEval.VALUE_INVALID);
            }

            int srcCellRow = ec.RowIndex;
            int srcCellCol = ec.ColumnIndex;

            double start;
            int    days;

            double[] holidays;
            try
            {
                start = evaluator.EvaluateDateArg(args[0], srcCellRow, srcCellCol);
                days  = (int)Math.Floor(evaluator.EvaluateNumberArg(args[1], srcCellRow, srcCellCol));
                ValueEval holidaysCell = args.Length == 3 ? args[2] : null;
                holidays = evaluator.EvaluateDatesArg(holidaysCell, srcCellRow, srcCellCol);
                return(new NumberEval(DateUtil.GetExcelDate(WorkdayCalculator.instance.CalculateWorkdays(start, days, holidays))));
            }
            catch (EvaluationException)
            {
                return(ErrorEval.VALUE_INVALID);
            }
        }