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\DateTimeExcel;
4
 
5
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
7
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
8
 
9
class TimeParts
10
{
11
    use ArrayEnabled;
12
 
13
    /**
14
     * HOUROFDAY.
15
     *
16
     * Returns the hour of a time value.
17
     * The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).
18
     *
19
     * Excel Function:
20
     *        HOUR(timeValue)
21
     *
22
     * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
23
     *                                    PHP DateTime object, or a standard time string
24
     *                         Or can be an array of date/time values
25
     *
26
     * @return array|int|string Hour
27
     *         If an array of numbers is passed as the argument, then the returned result will also be an array
28
     *            with the same dimensions
29
     */
30
    public static function hour(mixed $timeValue): array|string|int
31
    {
32
        if (is_array($timeValue)) {
33
            return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue);
34
        }
35
 
36
        try {
37
            Helpers::nullFalseTrueToNumber($timeValue);
38
            if (!is_numeric($timeValue)) {
39
                $timeValue = Helpers::getTimeValue($timeValue);
40
            }
41
            Helpers::validateNotNegative($timeValue);
42
        } catch (Exception $e) {
43
            return $e->getMessage();
44
        }
45
 
46
        // Execute function
47
        $timeValue = fmod($timeValue, 1);
48
        $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
49
        SharedDateHelper::roundMicroseconds($timeValue);
50
 
51
        return (int) $timeValue->format('H');
52
    }
53
 
54
    /**
55
     * MINUTE.
56
     *
57
     * Returns the minutes of a time value.
58
     * The minute is given as an integer, ranging from 0 to 59.
59
     *
60
     * Excel Function:
61
     *        MINUTE(timeValue)
62
     *
63
     * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
64
     *                                    PHP DateTime object, or a standard time string
65
     *                         Or can be an array of date/time values
66
     *
67
     * @return array|int|string Minute
68
     *         If an array of numbers is passed as the argument, then the returned result will also be an array
69
     *            with the same dimensions
70
     */
71
    public static function minute(mixed $timeValue): array|string|int
72
    {
73
        if (is_array($timeValue)) {
74
            return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue);
75
        }
76
 
77
        try {
78
            Helpers::nullFalseTrueToNumber($timeValue);
79
            if (!is_numeric($timeValue)) {
80
                $timeValue = Helpers::getTimeValue($timeValue);
81
            }
82
            Helpers::validateNotNegative($timeValue);
83
        } catch (Exception $e) {
84
            return $e->getMessage();
85
        }
86
 
87
        // Execute function
88
        $timeValue = fmod($timeValue, 1);
89
        $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
90
        SharedDateHelper::roundMicroseconds($timeValue);
91
 
92
        return (int) $timeValue->format('i');
93
    }
94
 
95
    /**
96
     * SECOND.
97
     *
98
     * Returns the seconds of a time value.
99
     * The minute is given as an integer, ranging from 0 to 59.
100
     *
101
     * Excel Function:
102
     *        SECOND(timeValue)
103
     *
104
     * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
105
     *                                    PHP DateTime object, or a standard time string
106
     *                         Or can be an array of date/time values
107
     *
108
     * @return array|int|string Second
109
     *         If an array of numbers is passed as the argument, then the returned result will also be an array
110
     *            with the same dimensions
111
     */
112
    public static function second(mixed $timeValue): array|string|int
113
    {
114
        if (is_array($timeValue)) {
115
            return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue);
116
        }
117
 
118
        try {
119
            Helpers::nullFalseTrueToNumber($timeValue);
120
            if (!is_numeric($timeValue)) {
121
                $timeValue = Helpers::getTimeValue($timeValue);
122
            }
123
            Helpers::validateNotNegative($timeValue);
124
        } catch (Exception $e) {
125
            return $e->getMessage();
126
        }
127
 
128
        // Execute function
129
        $timeValue = fmod($timeValue, 1);
130
        $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
131
        SharedDateHelper::roundMicroseconds($timeValue);
132
 
133
        return (int) $timeValue->format('s');
134
    }
135
}