1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial; |
4
|
|
|
|
5
|
|
|
use DateTimeInterface; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; |
9
|
|
|
|
10
|
|
|
class Helpers |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* daysPerYear. |
14
|
|
|
* |
15
|
|
|
* Returns the number of days in a specified year, as defined by the "basis" value |
16
|
|
|
* |
17
|
|
|
* @param mixed $year The year against which we're testing, expect int|string |
18
|
|
|
* @param int|string $basis The type of day count: |
19
|
|
|
* 0 or omitted US (NASD) 360 |
20
|
|
|
* 1 Actual (365 or 366 in a leap year) |
21
|
|
|
* 2 360 |
22
|
|
|
* 3 365 |
23
|
|
|
* 4 European 360 |
24
|
|
|
* |
25
|
|
|
* @return int|string Result, or a string containing an error |
26
|
|
|
*/ |
27
|
108 |
|
public static function daysPerYear(mixed $year, $basis = 0): string|int |
28
|
|
|
{ |
29
|
108 |
|
if (!is_int($year) && !is_string($year)) { |
30
|
|
|
return ExcelError::VALUE(); |
31
|
|
|
} |
32
|
108 |
|
if (!is_numeric($basis)) { |
33
|
1 |
|
return ExcelError::NAN(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
switch ($basis) { |
37
|
|
|
case FinancialConstants::BASIS_DAYS_PER_YEAR_NASD: |
38
|
|
|
case FinancialConstants::BASIS_DAYS_PER_YEAR_360: |
39
|
|
|
case FinancialConstants::BASIS_DAYS_PER_YEAR_360_EUROPEAN: |
40
|
54 |
|
return 360; |
41
|
|
|
case FinancialConstants::BASIS_DAYS_PER_YEAR_365: |
42
|
10 |
|
return 365; |
43
|
|
|
case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL: |
44
|
42 |
|
return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365; |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
return ExcelError::NAN(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* isLastDayOfMonth. |
52
|
|
|
* |
53
|
|
|
* Returns a boolean TRUE/FALSE indicating if this date is the last date of the month |
54
|
|
|
* |
55
|
|
|
* @param DateTimeInterface $date The date for testing |
56
|
|
|
*/ |
57
|
128 |
|
public static function isLastDayOfMonth(DateTimeInterface $date): bool |
58
|
|
|
{ |
59
|
128 |
|
return $date->format('d') === $date->format('t'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|