diff --git a/src/PhpSpreadsheet/Calculation/ArrayEnabled.php b/src/PhpSpreadsheet/Calculation/ArrayEnabled.php index bc852415b5..d2e6f3cf20 100644 --- a/src/PhpSpreadsheet/Calculation/ArrayEnabled.php +++ b/src/PhpSpreadsheet/Calculation/ArrayEnabled.php @@ -37,6 +37,27 @@ protected static function evaluateArrayArguments(callable $method, ...$arguments self::initialiseHelper($arguments); $arguments = self::$arrayArgumentHelper->arguments(); + return self::processArguments($method, ...$arguments); + } + + /** + * @param mixed ...$arguments + */ + protected static function evaluateArrayArgumentsSubset(callable $method, int $limit, ...$arguments): array + { + self::initialiseHelper(array_slice($arguments, 0, $limit)); + $trailingArguments = array_slice($arguments, $limit); + $arguments = self::$arrayArgumentHelper->arguments(); + $arguments = array_merge($arguments, $trailingArguments); + + return self::processArguments($method, ...$arguments); + } + + /** + * @param mixed ...$arguments + */ + private static function processArguments(callable $method, ...$arguments): array + { if (self::$arrayArgumentHelper->hasArrayArgument() === false) { return [$method(...$arguments)]; } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php index 8b40a2812e..007cce64ac 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php @@ -156,6 +156,7 @@ private static function decrementing(float $startDate, int $endDays, array $holi --$endDate; // Adjust the calculated end date if it falls over a weekend $endDow = self::getWeekDay($endDate, 3); + /** int $endDoW */ if ($endDow >= 5) { $endDate += 4 - $endDow; } @@ -188,6 +189,7 @@ private static function decrementingArray(float $startDate, float $endDate, arra } // Adjust the calculated end date if it falls over a weekend $endDoW = self::getWeekDay($endDate, 3); + /** int $endDoW */ if ($endDoW >= 5) { $endDate += -$endDoW + 4; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php index 3cfa92198d..3b73828ff5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; + class WorkDayTest extends AllSetupTeardown { /** @@ -49,4 +51,33 @@ public function providerWORKDAY(): array { return require 'tests/data/Calculation/DateTime/WORKDAY.php'; } + + /** + * @dataProvider providerWorkDayArray + */ + public function testWorkDayArray(array $expectedResult, string $startDate, string $endDays, ?string $holidays): void + { + $calculation = Calculation::getInstance(); + + if ($holidays === null) { + $formula = "=WORKDAY({$startDate}, {$endDays})"; + } else { + $formula = "=WORKDAY({$startDate}, {$endDays}, {$holidays})"; + } + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerWorkDayArray(): array + { + return [ + 'row vector #1' => [[[44595, 44596, 44599]], '{"2022-02-01", "2022-02-02", "2022-02-03"}', '2', null], + 'column vector #1' => [[[44595], [44596], [44599]], '{"2022-02-01"; "2022-02-02"; "2022-02-03"}', '2', null], + 'matrix #1' => [[[44595, 44596], [44599, 44600]], '{"2022-02-01", "2022-02-02"; "2022-02-03", "2022-02-04"}', '2', null], + 'row vector #2' => [[[44595, 44596]], '"2022-02-01"', '{2, 3}', null], + 'column vector #2' => [[[44595], [44596]], '"2022-02-01"', '{2; 3}', null], + 'row vector with Holiday' => [[[44596, 44599]], '"2022-02-01"', '{2, 3}', '{"2022-02-02"}'], + 'row vector with Holidays' => [[[44599, 44600]], '"2022-02-01"', '{2, 3}', '{"2022-02-02", "2022-02-03"}'], + ]; + } }