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 / DateTimeExcel / TimeParts.php

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

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