Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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 int|string $year The year against which we're testing
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): string|int
28
    {
29
        if (!is_numeric($basis)) {
30
            return ExcelError::NAN();
31
        }
32
 
33
        switch ($basis) {
34
            case FinancialConstants::BASIS_DAYS_PER_YEAR_NASD:
35
            case FinancialConstants::BASIS_DAYS_PER_YEAR_360:
36
            case FinancialConstants::BASIS_DAYS_PER_YEAR_360_EUROPEAN:
37
                return 360;
38
            case FinancialConstants::BASIS_DAYS_PER_YEAR_365:
39
                return 365;
40
            case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
41
                return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365;
42
        }
43
 
44
        return ExcelError::NAN();
45
    }
46
 
47
    /**
48
     * isLastDayOfMonth.
49
     *
50
     * Returns a boolean TRUE/FALSE indicating if this date is the last date of the month
51
     *
52
     * @param DateTimeInterface $date The date for testing
53
     */
54
    public static function isLastDayOfMonth(DateTimeInterface $date): bool
55
    {
56
        return $date->format('d') === $date->format('t');
57
    }
58
}