2
2
3
3
namespace PhpOffice \PhpSpreadsheet \Calculation \DateTimeExcel ;
4
4
5
+ use PhpOffice \PhpSpreadsheet \Calculation \ArrayEnabled ;
5
6
use PhpOffice \PhpSpreadsheet \Calculation \Exception ;
6
7
use PhpOffice \PhpSpreadsheet \Calculation \Functions ;
7
8
8
9
class WorkDay
9
10
{
11
+ use ArrayEnabled;
12
+
10
13
/**
11
14
* WORKDAY.
12
15
*
@@ -18,18 +21,32 @@ class WorkDay
18
21
* Excel Function:
19
22
* WORKDAY(startDate,endDays[,holidays[,holiday[,...]]])
20
23
*
21
- * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
24
+ * @param array| mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
22
25
* PHP DateTime object, or a standard date string
23
- * @param int $endDays The number of nonweekend and nonholiday days before or after
26
+ * Or can be an array of date values
27
+ * @param array|int $endDays The number of nonweekend and nonholiday days before or after
24
28
* startDate. A positive value for days yields a future date; a
25
29
* negative value yields a past date.
30
+ * Or can be an array of int values
26
31
* @param mixed $dateArgs
27
32
*
28
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
33
+ * @return array| mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
29
34
* depending on the value of the ReturnDateType flag
35
+ * If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
36
+ * will also be an array with matching dimensions
30
37
*/
31
38
public static function date ($ startDate , $ endDays , ...$ dateArgs )
32
39
{
40
+ if (is_array ($ startDate ) || is_array ($ endDays )) {
41
+ return self ::evaluateArrayArgumentsSubset (
42
+ [self ::class, __FUNCTION__ ],
43
+ 2 ,
44
+ $ startDate ,
45
+ $ endDays ,
46
+ ...$ dateArgs
47
+ );
48
+ }
49
+
33
50
// Retrieve the mandatory start date and days that are referenced in the function definition
34
51
try {
35
52
$ startDate = Helpers::getDateValue ($ startDate );
@@ -64,9 +81,9 @@ public static function date($startDate, $endDays, ...$dateArgs)
64
81
private static function incrementing (float $ startDate , int $ endDays , array $ holidayArray )
65
82
{
66
83
// Adjust the start date if it falls over a weekend
67
-
68
84
$ startDoW = self ::getWeekDay ($ startDate , 3 );
69
- if (self ::getWeekDay ($ startDate , 3 ) >= 5 ) {
85
+ /** int $startDoW */
86
+ if ($ startDoW >= 5 ) {
70
87
$ startDate += 7 - $ startDoW ;
71
88
--$ endDays ;
72
89
}
@@ -78,6 +95,7 @@ private static function incrementing(float $startDate, int $endDays, array $holi
78
95
++$ endDate ;
79
96
// Adjust the calculated end date if it falls over a weekend
80
97
$ endDow = self ::getWeekDay ($ endDate , 3 );
98
+ /** int $endDoW */
81
99
if ($ endDow >= 5 ) {
82
100
$ endDate += 7 - $ endDow ;
83
101
}
@@ -128,7 +146,8 @@ private static function decrementing(float $startDate, int $endDays, array $holi
128
146
// Adjust the start date if it falls over a weekend
129
147
130
148
$ startDoW = self ::getWeekDay ($ startDate , 3 );
131
- if (self ::getWeekDay ($ startDate , 3 ) >= 5 ) {
149
+ /** int $startDoW */
150
+ if ($ startDoW >= 5 ) {
132
151
$ startDate += -$ startDoW + 4 ;
133
152
++$ endDays ;
134
153
}
@@ -140,6 +159,7 @@ private static function decrementing(float $startDate, int $endDays, array $holi
140
159
--$ endDate ;
141
160
// Adjust the calculated end date if it falls over a weekend
142
161
$ endDow = self ::getWeekDay ($ endDate , 3 );
162
+ /** int $endDoW */
143
163
if ($ endDow >= 5 ) {
144
164
$ endDate += 4 - $ endDow ;
145
165
}
@@ -172,6 +192,7 @@ private static function decrementingArray(float $startDate, float $endDate, arra
172
192
}
173
193
// Adjust the calculated end date if it falls over a weekend
174
194
$ endDoW = self ::getWeekDay ($ endDate , 3 );
195
+ /** int $endDoW */
175
196
if ($ endDoW >= 5 ) {
176
197
$ endDate += -$ endDoW + 4 ;
177
198
}
0 commit comments