PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / Financial / Helpers.php

Helpers.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/Financial/Helpers.php

62 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Financial;
4
5 use DateTimeInterface;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
8 use TablePress\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 public static function daysPerYear($year, $basis = 0)
28 {
29 if (!is_int($year) && !is_string($year)) {
30 return ExcelError::VALUE();
31 }
32 if (!is_numeric($basis)) {
33 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 return 360;
41 case FinancialConstants::BASIS_DAYS_PER_YEAR_365:
42 return 365;
43 case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
44 return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365;
45 }
46
47 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 public static function isLastDayOfMonth(DateTimeInterface $date): bool
58 {
59 return $date->format('d') === $date->format('t');
60 }
61 }
62